+ Start a Discussion

How to create a new record in a related list with code?

I need to write some code to create a new record in a related list whenever a record is first created in the main object, and I don't even know where to start.
Bottom line, I'm trying to find a way to capture shared sale information without having to wait for SFDC to get around to it. (Management won't wait.) I've got a custom object "Shared Sale" that's a child to the master object Opportunities. It has 3 basic fields:
Percent Share
Volume Credit (calculated, based on Percent Share times Opportunity.Amount)
Whenever a new opportunity is created (just the first time), I need code that will create a "default record" in the Shared Sale object with the "Rep" field populated with the Owner, and the "Percent Share" set to 100. (Volume credit will take care of itself.) Otherwise, the sales person will have to remember to always create that record themselves - which means it will happen about 15% of the time, if I'm lucky. If it is a shared sale, they will go into the default record and change their own percent, then add the 2nd or 3rd person and their respective percents. But if it isn't shared, I still need a record in that related object with the owner given 100% credit.
I don't even know where to start looking to find the tools I need to do this. I think I need to write a Trigger, but that's just a guess. I'm a total newbie to programming in SFDC, but I've got a little coding under my belt in other apps. I'm very good at teaching myself, but I don't want to spend days hunting through the DFC trying to find the one piece of information I need. Can anyone point me in the right direction? Code words to search on, areas on DFC to focus my search on? Any help is greatly appreciated!
You can use APEX to do what you want to do.  Look at the following documentation: