5

I have created a trigger with several if statements, which has been working perfectly. However due to some changes in the business logic, a new field was added and needs to be included in the trigger.

The if statement I'm updating now, doesn't seem to work as intended, but I fail to see where the problem lies.

Basically, I have 3 fields:

Checkbox field: Branding

Checkbox field: Form completed

Picklist field: Customer Type <-- this is the new field

Previously, the following worked perfectly:

if(obj.Branding__c == true && obj.FormCompleted__c == false){
   Do Something;
}

Now the business logic specifies that for 2 customer types, the above should not apply (Form is not required), so I updated the if statement to:

if(obj.Branding__c == true && obj.FormCompleted__c == false && (obj.CustomerType__c != 'Type1' || obj.CustomerType__c != 'Type2')){
   Do Something;
}

Would anyone be able to identify the cause of my issue? To me it appears correct, but I've been looking at it too much to see the problem I guess.

Thanks in advance, Aaron

3

It is always either not one or not the other. Change your evaluation to:

static Set<String> whitelistedTypes = new Set<String> { 'Type1', 'Type2' };
// use the above in your Boolean evaluation:
if (obj.Branding__c && !obj.FormCompleted__c &&
    !whitelistedTypes.contains(obj.CustomerType__c))
{
    // do stuff
}
  • Thank you for being my eyes Adrian. That was totally the ticket and a big goof-up on my part :). Much appreciated! – Aaron Oct 9 '15 at 16:03

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.