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
raysfdc1988raysfdc1988 

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: trigger.new)
{
if(cp.Program_Name__c != null)
{
cp.name=cp.Program_Name__c;

}
}
}

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

https://help.salesforce.com/HTViewSolution?id=000005315

All Answers

asish1989asish1989
Auto number field can never be updated. 

https://help.salesforce.com/HTViewSolution?id=000005315
This was selected as the best answer
raysfdc1988raysfdc1988
thanks asish,

please any other solution..
Vinit_KumarVinit_Kumar
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.
raysfdc1988raysfdc1988
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....
Vinit_KumarVinit_Kumar
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 !!
raysfdc1988raysfdc1988
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)..eg..java13/05/2014
3. I am having attendence object which will used to update attendence for perticular course.
4.now 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...
Vinit_KumarVinit_Kumar
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.

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

Thanks vinit