+ Start a Discussion
CW5CW5 

Insert New Account Using Trigger

I've been bouncing around the forums and searching online, which I thought would be easy. How do you create a new record on the Account object inside of a trigger?

 

I want the new Account to have a name, record type, owner id, and that's it.

Best Answer chosen by Admin (Salesforce Developers) 
incuGuSincuGuS

 

trigger CreateAccount on myObj__c (after insert) {
        Account newA = new Account();
        newA.firstName = trigger[0].firstName__c ; // or whatever you need.
 newA.lastName = "lastName"; insert newA; }

 

 

This is a really simple trigger that works only when inserting one record at a time. If you need more info on trigger check this out:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_triggers.htm|SkinName=webhelp

 

All Answers

cloudcodercloudcoder

So you are saying on Account create, you want to make another new Account?

 

If so, first thing is that you are going to want to make sure you don't run into recursion issues (new account creates a new account creates a new account).

 

jbroquistjbroquist

Yes, please be more specific as to the exact requirements of your trigger.

incuGuSincuGuS

 

trigger CreateAccount on myObj__c (after insert) {
        Account newA = new Account();
        newA.firstName = trigger[0].firstName__c ; // or whatever you need.
 newA.lastName = "lastName"; insert newA; }

 

 

This is a really simple trigger that works only when inserting one record at a time. If you need more info on trigger check this out:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_triggers.htm|SkinName=webhelp

 

This was selected as the best answer