Skip to main content The new Salesforce certifications experience is live! Visit Trailhead Academy to explore your new certifications homepage.

Hello! Hoping for some help here, I'm having trouble wrapping my head around the query I'm trying to create for some reason. I have a page, and there are a set of demographics fields on this page. For each demographic field, there is a corresponding "opt-in" field. If the opt-in field is marked TRUE, the field should show on the page. If the corresponding opt-in field is marked FALSE, the field should not show. This is kind of what I have right now, which I know isn't right at all because it's not working correctly. I think I've confused myself with all the fields I've had to create for it. The example would be if I'm viewing the page with Sally's information and Sally has the EthnicitSelfDescribeOptIn__c = TRUE and GenderSelfDescribeOptIn__c = TRUE then I should be able to view the values she has entered for EthnicitySelfDescribe__c and GenderSelfDescribe__c. Since I all other opt-ins are set to FALSE, I should not see any other fields/information.

 

GenderSelfDescribe__c

 

SELECT FirstName,

 

NU__MiddleName__c,

 

LastName,

 

PersonEmail,

 

PersonMailingStateCode,

 

LeadershipPositions__c,

 

NU__Biography__pc,

 

NU__CasualName__c,

 

NU__Ethnicity__c,

 

NU__LinkedInAccount__c,

 

NU__FacebookAccount__c,

 

NU__Suffix__c,

 

PersonBirthdate,

 

PersonHomePhone,

 

PersonMobilePhone,

 

PersonTitle,

 

Salutation,

 

Website,

 

AreYouAFreeLancer__pc,

 

EthnicitySelfDescribe__c,

 

GenderSelfDescribe__c,

 

Transgender__pc,

 

WhatIsYourSexualOrientation__pc,

 

SexualOrientationSelfIdentification__pc,

 

IdentifyAsAPersonWithDisabilities__pc,

 

USArmedForcesMilitaryService__pc,

 

IMDBURL__pc,

 

OtherOrganizationsandMemberships__pc,

 

MediaOfExpertise__pc,

 

Representation__pc,

 

RepresentationPhoneNumber__pc,

 

BirthDecade__c

 

FROM ACCOUNT

WHEREId = {!id} AND BiographyOptIn__c = TRUE AND

 

CasualNameOptIn__c = TRUE AND

 

DecadeBorn_OptIn__c = TRUE AND

 

Disabilities_OptIn__c = TRUE AND

 

EmailOptIn__c = TRUE AND

 

EthnicitySelfDescribeOptIn__c = TRUE AND

 

Ethnicity_OptIn__c = TRUE AND

 

FacebookOptIn__c = TRUE AND

 

FreelancerOptIn__c = TRUE AND

 

GenderSelfDescribeOptIn__c = TRUE AND

 

Gender_OptIn__c = TRUE AND

 

HomePhoneOptIn__c = TRUE AND

 

IMDBURLOptIn__c = TRUE AND

 

LeadershipPositionsOptIn__c = TRUE AND

 

LinkedInOptIn__c = TRUE AND

 

MediaofExpertiseOptIn__c = TRUE AND

 

MiddleNameOptIn__c = TRUE AND

 

Military_OptIn__c = TRUE AND

 

MobilePhoneOptIn__c = TRUE AND

 

OtherOrganizationsMembershipsOptIn__c = TRUE AND

 

ProfessionalTitleOptIn__c = TRUE AND

 

RepresentationOptIn__c = TRUE AND

 

RepresentationPhoneOptIn__c = TRUE AND

 

SalutationOptIn__c = TRUE AND

 

SexualOrientationOptIn__c = TRUE AND

 

SuffixOptIn__c = TRUE

 

Any help is appreciated - thank you!
1 answer
  1. Dec 24, 2020, 2:30 PM
    Hi Amy,

     

    Could you give a little more background on where you are trying to use this query and what you are trying to do with it? Your WHERE clause filters the records returned by the query, but won't affect the fields selected by the query. Unless you want no record to be returned at all if even a single field is opted out, your WHERE clause should only have WHERE Id = {!id}.

     

    This might be an option, depending on what you're trying to do: Create a third set of fields (I know! lol) as formulas that conditionally display the value of the fields based on the opt-in flag.

     

    Hope this helps!
0/9000