2

Is it true that I cannot have OR or AND operators in if statements in APEX?

I have an object that has a picklist Code__c, and I need to execute some code if the code is set to either A or B.

How would I write something like:

if(pc.Code__c = 'A' || pc.Code__c = 'A') { }

Tia.

1
  • 1
    Might want to spend some time going through or reviewing the Apex Workbook. – crmprogdev Jan 10 '15 at 15:30
13

You need to use "==" for equality checks, as "=" is the assignment operator.

if(pc.Code__c == 'A' || pc.Code__c == 'B') { }

Due to the unfortunate nature of how SOQL is constructed, "=" is the equality operator in SOQL.

SELECT Id FROM ... WHERE SomeField__c = 'SomeValue'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.