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
RVJRVJ 

Save error. Expression cannot be assigned

Hi, I am trying to create a trigger to start an approval process after insert if a certain field is checked - we are getting this save error: 'Expression cannot be assigned'

 

 

MDFSubmitForApproval on MDF__c (after insert) {

for (MDF__c a : trigger.new) {


if (MDF__c.Submitted__c = 'true') {


Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();app.setObjectId(a.id);
Approval.ProcessResult result = Approval.process(app);
}
}
}

 

Not sure where we are going wrong with this?  Any help much appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
AshanAshan

And

IF (MDF__c.Submitted__c = true)

this should be

IF (a.Submitted__c == true)

All Answers

AshanAshan

if MDF__c.Submitted__c is a boolean value (Check box)

 

try

 

if (MDF__c.Submitted__c) 

or

if (MDF__c.Submitted__c == true) 

RVJRVJ

Thanks very much - but that did not work, we stll get the same error message - yes, this is a checkbox field.

AshanAshan

what is the line and column of the error?

RVJRVJ

It is now statng the same message but says at Line 0

 

trigger

MDFSubmitForApproval onMDF__c (afterinsert) {

 

 

for

(MDF__c a : trigger.new) {

 

IF (

MDF__c.Submitted__c = true) {

 

Approval

.ProcessSubmitRequest app = newApproval.ProcessSubmitRequest();

app.setObjectId(a.id);

Approval

.ProcessResult result = Approval.process(app);

 

}

}

}

AshanAshan

1) if (MDF__c.Submitted__c = true)

     this should be

     if (MDF__c.Submitted__c == true)

     or

     if(MDF__c.Submitted__c)

2) afterinsert should be after insert

AshanAshan

1) if (MDF__c.Submitted__c = true)

       this will not give a save error. But this is logically wrong.

2) your save error was caused by "afterinsert"

 

 

AshanAshan

And

IF (MDF__c.Submitted__c = true)

this should be

IF (a.Submitted__c == true)

This was selected as the best answer
RVJRVJ

Thank you very much - the == and the a. helped a lot - now onto the next challenge! ;-)