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
Nitish 73Nitish 73 

Comparison arguments must be compatible types

Hi All, 

I am trying to conditionally run a trigger with an IF condition.

But this is the error I get

"Comparison arguments must be compatible types"


Here is my code. My requirement is that, this trigger has to run when the Status is not 'Approved' or 'Issued'
trigger Insert_Junction on Authorizations__c (After update) {
if(Authorizations__c.Status__c<>'Approved' || Authorizations__c.Status__c<>'Issued'){
    CreateJunction createjunction = new CreateJunction();
    createjunction .createJunctionRecord(trigger.new);
}
}

Any help is appreciated. 


Thanks
Nitish
Best Answer chosen by Nitish 73
pconpcon
This is because you are using the object and not the actual object itself.
 
trigger Insert_Junction on Authorizations__c (after update) {
    for (Authorizations__c auth : Trigger.new) {
        if (auth.Status__c != 'Approved' || auth.Status__c != 'Issued') {
            CreateJunction createJunction = new CreateJunction();
            createJunction.createJunctionRecord(auth);
        }
    }
}

Note that this will fire on all because != || != will always be true.

All Answers

pconpcon
This is because you are using the object and not the actual object itself.
 
trigger Insert_Junction on Authorizations__c (after update) {
    for (Authorizations__c auth : Trigger.new) {
        if (auth.Status__c != 'Approved' || auth.Status__c != 'Issued') {
            CreateJunction createJunction = new CreateJunction();
            createJunction.createJunctionRecord(auth);
        }
    }
}

Note that this will fire on all because != || != will always be true.
This was selected as the best answer
pconpcon
"This is because you are using the object and not the actual object itself."

That should read:

"You are using the object name and not the reference to the object from the trigger class."

You have to pull the object out of the Trigger class and operate on that if you want to compare what it's value is.  And you want to do this for more than just Trigger.new.get(0) because you want to make sure your trigger works on bulk data.
Nitish 73Nitish 73
Thanks Patrick. Worked like a charm. 

Also, thanks for the headsup about the != || != , i replaced it with the other options on which this should fire. Made the condition a little longer, but it works. 


Thanks a lot.

Nitish