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
BenPBenP 

OR statement failing

I'm trying to get the class code to throw an error if the country code is not equal to "US" or "CA".  For some reason I get the error on everything with the statement below.  Any ideas?

 

 

if(caseNo.Contact.MailingCountry != 'US')// || caseNo.Contact.MailingCountry != 'CA')
                {ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Sales Order cannot be created, no shipping outside the US or Canada.');
                        ApexPages.addMessage(msg);
                        ErrorFlag=true;
                }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
CoryCowgillCoryCowgill

I believe you want to do an AND not an OR. If its not equal to US and it not equal to CA. The or statement you have below will always be true.

 

Your If statement below will always be true becuase even it MalingCounter == US, US != CA, so your second condition will be true and vice versa.

All Answers

CoryCowgillCoryCowgill

I believe you want to do an AND not an OR. If its not equal to US and it not equal to CA. The or statement you have below will always be true.

 

Your If statement below will always be true becuase even it MalingCounter == US, US != CA, so your second condition will be true and vice versa.

This was selected as the best answer
BenPBenP

Thank you, I think I confused myself somehow.

 

Nothing like a fresh set of eyes.