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
Peter KempPeter Kemp 

System.SObjectException: DML statment cannot operate on trigger.new or trigger.old

Hi,

I'm still working on this old code base that I've inherited and when it comes to commiting an application the following routine fails to execute.  Again, there was no error handling code but I managed to extract the error from the trace.  Code is as follows:

Code:
public sforce.SaveResult[] updateUserRecruimentDetails(String recStatus, String recStage, String unsubSubstage, String appSubstage, string userId, sforce.SforceService binding)
{
 // NB if you change the names of the recruitment status, stage or sub-stage fields 
 // then you will have to export a new wsdl file then change the code below
 sforce.QueryResult qr = binding.query("Select Id from Contact where Id='" + userId + "'");
 sforce.sObject[] results = qr.records;
 sforce.Contact contact = (sforce.Contact)results[0];
 contact.Recruitment_Status__c = recStatus;
 contact.Recruitment_Stage__c = recStage;

 if(!unsubSubstage.Equals(""))
 {
  contact.Unsubmitted_sub_stage__c = unsubSubstage;
 }

 if( recStage.Equals("Unsubmitted") )
 {
  contact.Unsubmitted_sub_stage__c = appSubstage;
 }
 else if( recStage.Equals("Application") )
 {
  contact.Application_sub_stage__c = appSubstage;
 }
 else if( recStage.Equals("Assessment Centre") )
 {
  contact.Assessment_Centre_sub_stage__c = appSubstage;
 }
 else if( recStage.Equals("Offer") )
 {
  contact.Offer_sub_stage__c = appSubstage;
 }
 sforce.sObject[] records = {contact};
 sforce.SaveResult[] saveResults = binding.update(records);
 return saveResults;
}

called from:

Code:
contact.updateUserRecruimentDetails("Applying", "Application", "Submitted application", "Awaiting 2 screenings", userId, binding);

Brings up the error:

message = "WebApplicationSubmission: execution of BeforeUpdate\n\ncaused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old\n\nClass.ApplicantConversion.BaseConverter.associateWithAccount: line 53, column 13\nClass.ApplicantConvers...

i presume this is a system error, event though it does have a spelling mistake in it. The datatypes for the
Assessment_Centre_sub_stage__c etc are all pick lists and they used to work fine. Any ideas?

Thanks

Pete
SuperfellSuperfell
Its an error from an apex trigger, you'll have to review the apex code for your trigger ApplicantConversion.BaseConverter.associateWithAccount
Peter KempPeter Kemp
That would explain it.  Not my side of the development team, I'll get in touch with them.  Thanks!

Pete