trigger CloneOpp on Opportunity (after update){
Custom_Object__c[] ls=new Custom_Object__c[]{};
for(Opportunity o: trigger.new){
Custom_Object__c obj=new Custom_Object__c();
//Assign whichever values you want to clone to the fields of your custom object, for example:
//obj.name=o.name;
ls.add(obj);
}
insert ls;
}
Hi, I have a slight confusion understanding your requirement. Correct me if I am wrong, Do you want to clone the opportunity record to your custom object everytime a new opportunity is inserted?
trigger CloneOpp on Opportunity (after update){
Custom_Object__c[] ls=new Custom_Object__c[]{};
for(Opportunity o: trigger.new){
Custom_Object__c obj=new Custom_Object__c();
//Assign whichever values you want to clone to the fields of your custom object, for example:
//obj.name=o.name;
ls.add(obj);
}
insert ls;
}
i want to clone opportunity object in custom object and then if i insert new opportunity in opportunity object it should get updated in custom object .same question how to do this dynamically??
Your trigger should look something like this:
Let me know if it helps.
Thanks!
All Answers
I have a slight confusion understanding your requirement. Correct me if I am wrong, Do you want to clone the opportunity record to your custom object everytime a new opportunity is inserted?
Your trigger should look something like this:
Let me know if it helps.
Thanks!
i'm not able to access standard object fields it's giving error like:Variable does not exist: stage
Thanks!
You are using incorrect field name. The API name of opportunity stage is 'StageName'.
yes bro i got that but can you tell me tell how to execute that trgger??
This trigger will get executed automatically when you create an opportunity.
Minor correction*
In the first line of your trigger, change after update to after insert.
Thanks bro!!
You're welcome. :)
Please mark the best answer so that others facing similar problem can benefit from this post.
Thanks!
Because the trigger is dynamic in it's own context.
i want to acces all fields from opportunity object into custom object without using field name so how can i do that?
I don't think that it's possible. You have to define how you want your automation process to work.
I want to compare standard object fields with custom object fields in trigger how to do that??
Can you tell me the on what basis you want to compare those fields?
If opportunity name,date ,stage equal with custom object fields then we can insert that record
I want to match the labels of the fields.