1

-> I have a field say Amount in Opportunity Object.

-> I have created a Validation Rule that If Amount is empty/null throw an error.

-> I have a workflow which will fire on creation of Opportunity, to empty the Amount field.

Now when I create an Opportunity, It creates a record with Amount field as empty.

-> Now I have created a trigger After Update Trigger, which will update another field in Opportunity, say a checkbox Revised Opportunity.

Now whenever I try to create an Opportunity there is an error caused due to trigger and after that validation rule.

I checked the debug log, I am able to see an Opportunity ID related to my newly created Opportunity and error message it displays in debug log is "Record is Read Only". I want to know how does this works? Does my record gets deleted(which I don't see in the log as being deleted) Or does the Process is not committed/rollback happens?

Because I tried creating an auto number(created two records with trigger as inactive and activated trigger and after two fails, I again inactivated the trigger and tried to save and found autonumber being incremented by 2) thinking that it won't get incremented in failing record save but auto number does get incremented. So, does it mean that my record is getting deleted in the Order of Execution?

  • I have two questions: 1) Why you are not updating revised opportunity field using workflow? 2) You said your trigger fires on after update then why is it firing when you are creating an opportunity? It will be better if you share your code. – Mahmood Oct 28 '16 at 10:18
  • after triggers that attempt to do updates on Trigger.new will get the read-only error - you need to clone the sobject and do DML on the clone – cropredy Oct 28 '16 at 17:16
1

You are able to create records with empty Amount field because if a workflow field updates a record,custom validation rules, duplicate rules, and escalation rules are not run again.

From Salesforce Documentation

If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.

The Autonumber is incremented because of the partial save that happens before your after update triggers fire. You cannot make changes to the record in after update trigger because it has already went through partial save and becomes Read only.

You record is not commited because an error has occured and transaction is rolled back.

  • But if i try to deactivate the validation rule, the record should get saved as there is no check before save. And ofcourse there would be a Read Only error message from the trigger. But the record still doesnt gets saved even if I deactivate the validation rule. Secondly, if its a rollback, I thought Auto Number should also get rollbacked instead of that(field) alone get comitted and the rest(record) getting rollback. – C. Praveenkumar Oct 28 '16 at 11:35
  • If you deactivate the validation, if you try to modify the record in after update trigger, you will still get error and transaction will roll back(Assuming that there is one record in trigger.new). The auto number are not rolled back maybe due to the fact that they are generated via some other tanks in Salesforce and not the object table for the record. – manjit5190 Oct 29 '16 at 4:04
  • If it does gets deleted, I expected the error msg for revisiting the record should show "Record Deleted" instead of "Data not available" (coz this pose a wrong scenario that it might be available later). – C. Praveenkumar Nov 1 '16 at 12:31
0

I don't have the repo to comment, so writing here. I followed your steps, as manjit mentioned everything happening but I don't see any delete operation on debug log??? In debug log it shows it created a record but if I try to access that record it says Data not available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.