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
mukesh guptamukesh gupta 

Script stop on addError in apex

Hi Expert,

I am using add error method, when criteria match then addError method call, but here script doenot stop and execute next loop.

i want to stop script when addError call. i have used break; return; but nothing happen

 
for (Opportunity currOpp: newOpportunities_1){
              System.debug('currOpp name '+currOpp.name);
            if (currOpp.RecordTypeId!=PMRecordTypeId.Id  ){
                currOpp.addError(Label.pmr);   
               
            }
          }

for (Opportunity currOpp: newOpportunities_2){
              System.debug('currOpp name '+currOpp.name);
         
          }

Thanks 
Mukesh

 
VinayVinay (Salesforce Developers) 
Hi Mukesh,

Try using return null;?

Thanks,
Abdul KhatriAbdul Khatri
Hi Mukesh,

Can you please share the code and the context in which are trying to achieve the required functionality?
Abdul KhatriAbdul Khatri
Hi Mukesh,

Were you able to get this working? You hasn't shared the code?