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

write trigger to update a field of same object

want to update a autonumber field from a another custom formula field of sam object..
here name is autonumer field and Program_Name__c is formula field.. when i create a record i need to update name field by Program_Name__c field...
pl help me

trigger updatename on Course_Program__c (after insert, after update) {

for(Course_Program__c cp:
if(cp.Program_Name__c != null)


getting error:Field is not writeable: Course_Program__c.Name at line 7 column 1
Best Answer chosen by raysfdc1988
Auto number field can never be updated.

All Answers

Auto number field can never be updated.
This was selected as the best answer
thanks asish,

please any other solution..
Any reason you are using AutoNumber field,if you want to copy Program_Name__c field value.

You can create a Text field instead of Auto Number field.
hi vinit..

I dont want this autonumber field but if change the field then.. then i need to enter a program name.. but i have already custom formula filed called Course_Program__c.. which i am using as name.. so now i need update name field this Course_Program__c....
Again,I don't understand whta is the purpose of having this auto number field,if you are already using custom field for name.

The design does not look good to me !!
lemme explain indetail..

1.there is object called course program... and the its standard field is autonumber field i,e Name
2. I am having a field called course program name.. which is formula field(date+some picklistvalue)
3. I am having attendence object which will used to update attendence for perticular course. I am creating a console to update attendence..but in attendance page i need to desplay this course program name instead of autonumber..

I can change the field type but again i need to change wsdl...
See thats what I meant by flaw in design,why did you have autonumber field in first place if the name would be populated with some Formula.

1.) Being a standard field,you can't remove it from Standard layout.The only option I think is to change the field type and generate a new WSDL file.

2.) If it's a VF page for attendance then you can make it hidden.

yeah you are right..
I will go with 1st option..

Thanks vinit