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, 2015 at 15:30

1 Answer 1

14

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .