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
Mahmoud Coudsi 1Mahmoud Coudsi 1 

Error: Invalid Data. Review all error messages below to correct your data. Apex trigger CheckEligiblityUponSelfSchedule caused an unexpected exception

Upon saving a lead record I get this error message:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger CheckEligiblityUponSelfSchedule caused an unexpected exception, contact your administrator: CheckEligiblityUponSelfSchedule: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.CheckEligiblityUponSelfSchedule: line 4, column 1

Any ideas? 

Here is my code:

Trigger CheckEligiblityUponSelfSchedule on Lead (after update) {
  
  for(Lead l: Trigger.new) {    
    if(l.self_scheduled__c = TRUE){
    Eligibility.runEligibilityCheck(l.id);
    }
  }
}
Raj VakatiRaj Vakati
Change it to before update  event .. After update the record will be read only and you cannt able to perfom DML
 
Trigger CheckEligiblityUponSelfSchedule on Lead (before update) {
  
  for(Lead l: Trigger.new) {    
    if(l.self_scheduled__c = TRUE){
    Eligibility.runEligibilityCheck(l.id);
    }
  }
}

 
v varaprasadv varaprasad
Hi,

Please check below code in if you have to use == for comparison.

 
Trigger CheckEligiblityUponSelfSchedule on Lead (before update) {
  
  for(Lead l: Trigger.new) {    
    if(l.self_scheduled__c == TRUE){
    Eligibility.runEligibilityCheck(l.id);
    }
  }
}


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Project Support: varaprasad4sfdc@gmail.com