You need to sign in to do that
Don't have an account?
Automatically create new record upon save
I originally posted the message below on the general salesforce question board, but there they told me to come here. So here I am! :-)
I would like Salesforce to automatically create (and save) a new record (for object B) as soon as I manually save a newly created record for object A that meets a certain condition (e.g. field A is not empty). With that I would like to prepopulate some object B fields with object A data.
(Right now I have a created a custom button on my object A record which does all of this, but pushing this button manually each time is not the ideal solution, so I would like this process to automatically take place in the background).
Is this feasible? If yes, how? :-)
Probably the answer will be "Yes, with Apex!", because always when I get stuck the problem can be solved using Apex or Visualforce.. Tbh, this is really frustrating since I'm just a simple administrator and not a developer.
So any help (e.g. some sample code, test class) would be more than appreciated!
Do the fields on Object B need to be populated with data from A? Or can they just be lookup formula fields?
How is B related to A? Master-Detail, or lookup?
Objects A and B are not related to each other in any way.
Right now, the B-record is manually created by pushing a button on the A-record detail page.
Pre-populating the B-record with A-record ("Beursinput") data is done in the custom button code (see below)
Okay - without having access to your instance, I can't put the actual objects/field names in, but here's an example where any Opportunity (Object A) where type = 'Existing Customer - Upgrade', we'll create a new Contact (Object B) where Lastname = Opportunity Name, and Contact Title = Opportunity StageName.
So obviously not a real life example, but I think you can easily adapt it to do what you want...note that unlike with buttons, the fields names for both source and target have to be the API field names...
Best practice for triggers is to write a simple trigger, and then pass off handling to class...so first we have the class, and that class also contains a test script...
And then the trigger to call that class
That should get you started...
Hi Peter,
I really appreciate you trying to help me! The code below may be obvious to you and other developers, but it's like chinese to me, lol!
I have absolutely no experience with apex triggers, so I have no idea where to begin.
I always have to pass when the answer is "Apex" or 'Visualforce". I kinda expected this, nevertheless it's again frustrating not being able to implement a possible improvement to our Salesforce environment!
Anyway, thanks for your feedback!
Regards,
Martijn