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
SewaltherSewalther 

Compile Error: Variable does not exist: when adding criteria to Trigger

Hello Community,

I have a trigger on the Lead that I would like to execute only when the Lead custom_field_1_c is not populated and Lead custom_field_2_c has the value of approved, but I keep having either syntax errors or an error saying that my variable does not exist. Any help would be appreciated. I have included my current trigger & class that aren't throwing errors. Thank you!

My Current Trigger (not giving an error):
trigger SalesCloudOnboardLead on Lead (after insert, after update) {
for(Lead leadRecord : Trigger.New){
SalesCloudOnboardClass.makeCallout(leadRecord.Id,'Lead');
    }
}

My Current Trigger (giving an error):
trigger SalesCloudOnboardLead on Lead (after insert, after update) {
for(Lead leadRecord : Trigger.New){
(Lead.custom_field_1_c=null && Lead.custom_field_2_c==('Approved'));
SalesCloudOnboardClass.makeCallout(leadRecord.Id,'Lead');
    }
}

My Class (not giving an error):
global class SpheraCloudOnboardClass {
    @future(callout=true)
    public static void makeCallout(String recordID,String recordType) {
    String endpoint='';
      
    if(recordType == 'Lead'){
     endpoint = 'https://demo.salessolutions.com/onboard/trial/type/Lead/id/'+recordID;
        }else if(recordType == 'Contact'){
             endpoint = 'https://demo.salessolutions.com/onboard/trial/type/Contact/id/'+recordID;
          }
               
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        request.setEndPoint(endpoint);
        // Set the HTTP verb to POST.
        request.setMethod('POST');
        // Send the HTTP request and get the response.
        HttpResponse response = new HTTP().send(request);
        }
   }
v varaprasadv varaprasad
Hi ,

Use == when comparing two values :

Lead.custom_field_1_c==null && Lead.custom_field_2_c==('Approved'))​
My Current Trigger (giving an error):
trigger SalesCloudOnboardLead on Lead (after insert, after update) {
for(Lead leadRecord : Trigger.New){
(Lead.custom_field_1_c==null && Lead.custom_field_2_c==('Approved'));
SalesCloudOnboardClass.makeCallout(leadRecord.Id,'Lead');
    }
}

Hope it helps you.

Thanks
Varaprasad



 
JitukawaleJitukawale
Code if your If block is incorrect. Use below code.
trigger SalesCloudOnboardLead on Lead (after insert, after update) {
for(Lead leadRecord : Trigger.New){
(leadRecord.custom_field_1_c == null && leadRecord.custom_field_2_c=='Approved');
SalesCloudOnboardClass.makeCallout(leadRecord.Id,'Lead');
    }
}

Let me know if you face any problem.

Regards,
Jitendra Kawale