You need to sign in to do that
Don't have an account?
Steve Connelly
Need to create new custom object records from Opportunity record plus fields from another custom object.
Working in Lightning....
I am new to APEX. I nee dto build a trigger to create a custom object record from an Opportunity when a new Opp is created or the Close date changes.
I need to use fields from the Opp and from another custom object in the new record.
Can anyone point me to an article or some basic code to get me started?
There is more to this but I just want to get to whewre I can create the new record first. Sort of a learn by doing process.
Any help or suggestions is greatly appreciated.
Best regards,
Steve
I am new to APEX. I nee dto build a trigger to create a custom object record from an Opportunity when a new Opp is created or the Close date changes.
I need to use fields from the Opp and from another custom object in the new record.
Can anyone point me to an article or some basic code to get me started?
There is more to this but I just want to get to whewre I can create the new record first. Sort of a learn by doing process.
Any help or suggestions is greatly appreciated.
Best regards,
Steve
Maybe the below blogs might help you check it once,
https://success.salesforce.com/apex/answers?id=90630000000DLraAAG
https://success.salesforce.com/answers?id=9063A000000lDTUQA2
Thanks.
All Answers
Maybe the below blogs might help you check it once,
https://success.salesforce.com/apex/answers?id=90630000000DLraAAG
https://success.salesforce.com/answers?id=9063A000000lDTUQA2
Thanks.
Probably my fault for not going into greater detail.
I won't be able to use a Process Builder, Workflow or flow for this, i will need a trigger.
The end result I need is to create a new record for each quarter an Opportunity is scheduled to be open based upon the Created date and the Close date.
I have a custom object (Quarter Number) that has a record for each quarter for a number of years (Q1-2019, Q2-2019, Q3-2019, Q4-2019, Q1-2020, Q2-2020, and so fortht. These records also have an index number (1,2, 3, 4, etc).
I have created formula fields on the Opp that show the quarter that the opp was created based upon the Created date and the number of quarters that the Opp spans as well as the average Amount for each quarter.
Then I have a last custom object (Open Quarter) that is the record i want to create which will show the quarter number and the avg amount for each quarter plus a few other things. I need to create one of these records for each quarter the Opp spans. So if the Opp was created on February 14th 2019 and has a close date of June 3rd 2020 then it spans 6 quarters and I will need 6 records, like this: Q1-2019, Q2-2019, Q3-2019, Q4-2019, Q1-2020, Q2-2020. This will allow me to create some particular forcasting reports.
The trigger needs to do the following:
I did not go into all the detail as I just wanted to take this a step at a time and learn as i go. But as you can see above, I think that a trigger is the way that I have to go. I am fairly adept with Lightning Flow Builder but could not figure out a way to loop this process within a flow. This is why I am working on a trigger.
So I had planned to first build the part where the trigger grabs the Opp ID and required fields (when the trigger fires) and then build the part where it creates a new record with that data.
Then I was going to work on the loop by matching the index record based upon the starting quarter and then iterate the loop based upon the quarters spanned filed.
And the then bat clean-up on other details like removing existing records if the close date changes, etc.
Now if my thinking about how to approach the peices are all wrong, I am open to suggestions. As I mentioned, I am crand new to coding and so I understand that what I have come up with may not be the best way.
But in the end, this is the project and I am pretty sure that a trigger is the best way to go.
And so I am looking for existing pieces that I can use as guides to build what I need.
Any other suggestions or thoughts?
Best regards,
I do get this error in the sandbox:
Sandbox
Apex script unhandled trigger exception by user/organization: 00541000002c4kS/00D0j000000DCsc Source organization: 00D4100000137pQ (null)
createOq: execution of AfterUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.createOq: line 26, column 1