0
votes

When checking the value of a boolean and requiring to set a string value (using a ternary operator) in salesforce, is there a short process for this.

For example with the following I get an error: pipeDelimitedLead += aLead.SMS_Opt_In__c == '1|' ? '0|':

error: Comparison arguments must be compatible types: Boolean, String

is there a quick way of doing this without requiring an if/else statement?

Thanks.

1
Is that actually what you have in your code? That's not a valid ternary structure -- it needs to be like <comparison>?<if_true>:<if_false>. You don't have anything in the false section of that ternary operator. I suspect maybe you mean pipeDelimitedLead += aLead.SMS_Opt_In__c?'1|':'0|', which may be valid but is still majorly awkward. - amrcn_werewolf
Thank you. That's what I get for trying to complete something in a hurry. Thanks for pointing out my error! - SalesforceQueries

1 Answers

0
votes

It is also a ternary operator but not mostly used in salesforce. You can do this by following.

pipeDelimitedLead += (aLead.SMS_Opt_In__c==1?aLead.SMS_Opt_In__c:0),