-3

I have this code that sends information to a webhook, I only need to send information when the field WebTrig__c (checkbox) = True. I wrote this code but for both cases it sends the information to the webhook

trigger OpportunityWebhookTrigger on Opportunity (after update) {
    String url = 'https://hook.integromat.com/yidd9alvv698pu6ki5gpzu666nvsjyr';
    String content = Webhook.jsonContent(Trigger.new, Trigger.old);
        
    for(Opportunity c : [Select WebTrig__c From Opportunity Where Id in :Trigger.newMap.keySet()]){
        if(c.WebTrig__c = true ){
            Webhook.callout(url, content); 
            Break;  
        }
        else if(c.WebTrig__c = false) {
            break;
        }
    }
}

1 Answer 1

1

if you're comparing booleans in an if statement you should use equality operator - '==' instead of single '='.

1
  • 4
    Though if(condition == true) can be simplified to if(condition), and if(condition == false) can be simplified to if(!condition). In general, there's no need to compare two booleans (they can be used directly).
    – Derek F
    Commented Jan 3, 2022 at 12:10

You must log in to answer this question.

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