function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
symantecAPsymantecAP 

Select Picklist in Apex code

Hi My code is accepting fields from a client and one of the fields is a Picklist field. The code should have the field value coming from client to the filed value in database else should return a response. I have written a logic below but thats not working. And the logic is confined to the values in database today. If the values are changed in future the code wont b valid.

 if (CalltoActionType!='Datasheet'||CalltoActionType!='Analyst Report/Research'||
             CalltoActionType!='Article/Editorial'||CalltoActionType!='Branding/Advertisement'||
             CalltoActionType!='Customer Reference'||CalltoActionType!='eBook/Yellowbook'||
             CalltoActionType!='eLearning/Training'||CalltoActionType!='Event - 3rd Party'||
             CalltoActionType!='Event - Symantec'||CalltoActionType!='Infrastructure'||
             CalltoActionType!='Leads/Data'||CalltoActionType!='Multimedia'|| 
             CalltoActionType!='Newsletter - 3rd Party'||CalltoActionType!='Newsletter - Symantec'||
             CalltoActionType!='Non-lead generating Collateral'||CalltoActionType!='Podcast'||
             CalltoActionType!='Product Tour'||CalltoActionType!='Renewal Notification'||
             CalltoActionType!='Sales Incentive / Purchase'||CalltoActionType!='Sales Tools'||
             CalltoActionType!='SYMC Webpage(s)'||CalltoActionType!='Trialware'||
             CalltoActionType!='Webcast'||CalltoActionType!='White Paper'||
             CalltoActionType!='STS & SSE'||CalltoActionType!='3RD PARTY WEBSITE')
             {
             system.debug(response3+'TESTING MODE');
             return response3 ;

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Nick34536345Nick34536345

Hi,

 

Your condition is always true, for any value of CalltoActionType.

 

To avoid hard coding the values perhaps you can describe the field using getDesribe() and then calling getPicklistValues() will give you a list of values taht you can check against.

 

 

All Answers

Nick34536345Nick34536345

Hi,

 

Your condition is always true, for any value of CalltoActionType.

 

To avoid hard coding the values perhaps you can describe the field using getDesribe() and then calling getPicklistValues() will give you a list of values taht you can check against.

 

 

This was selected as the best answer
symantecAPsymantecAP

Thank you Nick

 

I used the describe global() with get pick list values() method. and that  solved the issue.