If you want to create an opportunity when an account is created in sales force, then you can use the “after trigger” to create opportunity automatically. Below is the example of sales force “after trigger”.
Related Read: 4 Lightning UI Features You Must Know
Below code will automatically create an Opportunity when an Account is created in your sales force org.
1 2 3 4 5 6 7 8 9 10 11 12 |
trigger AutoOpp on Account(after insert) { List<Opportunity> newOpps = new List<Opportunity>(); for (Account acc : Trigger.new) { Opportunity opp = new Opportunity(); opp.Name = acc.Name + ' Opportunity'; opp.StageName = 'Prospecting'; opp.CloseDate = Date.today() + 90; opp.AccountId = acc.Id; // Use the trigger record's ID newOpps.add(opp); } insert newOpps; } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.