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

Trigger to update Quote Name with Custom Auto-Number Field



I'm trying to hack my way around making the Quote Name auto-populate with a custom number field


Below is the trigger that does not work, I was only able to add a specific value into the Quote Name field. 


I need the trigger to put the value of the custom quote auto-number field Quote_Number__c.


Any ideas? Thanks!



trigger QuoteTrigger on Quote (before insert) {

for(Quote q : {

q.Name = q.Quote_Number__c;


Imran MohammedImran Mohammed



You should have after insert trigger. Below is the code you should have.

Let me know if you have any issues.


trigger QuoteTrigger on Quote (after insert) {
List<Quote> quoteList = new List<Quote>();
for(Quote q : {

q.Name = q.Quote_Number__c;
update quoteList;



After I applied the trigger, I tried to create a new quote, leaving the Quote Name empty, but since it's a required field, it asked me to enter a value, so I did and recieved this error message:

Error: Invalid Data.

Review all error messages below to correct your data.
Apex trigger QuoteTrigger caused an unexpected exception, contact your administrator: QuoteTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.QuoteTrigger: line 6, column 1


I wish it was as simple as changing the Quote Name to an auto-number field.  This is possible with Custom Objects.  I need the Quote Name to populate with a custom number, that's why I created a custom auto-number field with the attempt to link it to the Quote Name.  I don't want the user to worry about entering anything in the Quote Name. 






Hi Jeremy


You cannot update the record you are evaluating in  after triggers.  You best option for this would be to use Workflow to populate this field (additional advantages to this solution is you do not need any test code, or if you decide you no longer what to rename your quotes, you can easily disable).


Hope this helps