You need to sign in to do that
Don't have an account?
Steve Connelly
How do i pull an opportunity ID into an Apex trigger?
I am new to coding in general and to Apex in particular so any help I can get is greatly appreciated.
I am building a trigger that will create a new custom object record from an opportunity.
I plan to use process builder to fire the trigger when a particular opp type is created or when a particular field in that opp is updated.
I want the new record to be related to the Opp so i want to pull the Opp ID and some of the fields into the trigger to use in the new record.
How do i pull that specific data in?
Like I said, I am new at this but willing to work and learn.
Best regards,
Steve
I am building a trigger that will create a new custom object record from an opportunity.
I plan to use process builder to fire the trigger when a particular opp type is created or when a particular field in that opp is updated.
I want the new record to be related to the Opp so i want to pull the Opp ID and some of the fields into the trigger to use in the new record.
How do i pull that specific data in?
Like I said, I am new at this but willing to work and learn.
Best regards,
Steve
This trigger is written on your custom object so there will be some logic on your opportunity trigger to populate the opp on custom object or to create custom object whenevr new opp created.
For basic of apex trigger go through the below urls:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers
Thanks!
Chirag
All Answers
Here is the sample code for you.
Create trigger on the custom object. Hope it will help you to write your trigger.
Please mark this as the best answer if it resolve your issue.
Thanks!
Chirag
Question, if this is set to run on the custom object, how will it know to fire when a new Opp is created or updated?
Sc
Is that correct?
Sc
At line 1, we have used the context that means when the trigger should fire.
At line 4, we've given the condition either insert or update in both condition it will take the opportunity id from custom object and will add those in the set of id's.
Thanks!
Chirag
This trigger is written on your custom object so there will be some logic on your opportunity trigger to populate the opp on custom object or to create custom object whenevr new opp created.
For basic of apex trigger go through the below urls:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers
Thanks!
Chirag
I had thought that the trigger would need to run on the Opp to pull in the ID and fields so i could use them in the creation of the custom record.
Sc