You need to sign in to do that
Don't have an account?

Trigger
Hello
I have a custom object related to opportunity.
What i need: When an opportunity is closed won, this opportunity is created on my custom object.
I have to use triggers to do that?
Thanks!
I have a question here, how are you mapping Opportunity to Custom Object?
Or are you copying the entire Opportuinity to Custom Object?
I have a Master-Detail Relationship with Opportunity in my Custom Object, but the opportunities are not mapped yet.
I'm new on SF, how can I do that?
I dont want to show all opportunities fields in my custom object, but i can hide what I don't need if I copy the entire oportunity, right?
Thanks!!
One more question,when Opportunity stage reaches Closed Won , at that time does the Custom object record already exists or at that time you want to create a new record for that custom object.
I want to create a new record when the stage reaches Closed Won. The Custom object record doesn't exist yet.
Thanks!
Felipe.
Hi,
Below is the code you should use. Make the changes accordingly.
{
CustomObject__c[] coList = new CustomObject__c[]{};
for(Opportunity o: Trigger.new)
{
if(o.StageName == 'Closed Won')
{
CustomObject__c co = new CustomObject__c(Assign all the fields you want here, <<OpportunityLookupFieldOfCustomObject__c>> = o.id); // Replace <<OpportunityLookupFieldOfCustomObject__c>> with your custom field that is a lookup to opportunity
coList.add(co);
}
}
insert coList;
}
Let me know if you get any issues