You need to sign in to do that
Don't have an account?

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.
And
IF (MDF__c.Submitted__c = true)
this should be
IF (a.Submitted__c == true)
All Answers
if MDF__c.Submitted__c is a boolean value (Check box)
try
if (MDF__c.Submitted__c)
or
if (MDF__c.Submitted__c == true)
Thanks very much - but that did not work, we stll get the same error message - yes, this is a checkbox field.
what is the line and column of the error?
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);
}
}
}
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
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"
And
IF (MDF__c.Submitted__c = true)
this should be
IF (a.Submitted__c == true)
Thank you very much - the == and the a. helped a lot - now onto the next challenge! ;-)