Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. trigger createOnboardingOnOpportunityWon on Opportunity (after update) {
  2.  
  3. List <Onboarding__c> OnboardingToInsert = new List <Onboarding__c> ();
  4. // or whatever your custom object name put instead of Sponsorship__c
  5.  
  6. for (Opportunity o : Trigger.new) {
  7.  
  8.  
  9. // here is where you check if opportunity that is being inserted
  10. //meets the criteria
  11. if (o.StageName == 'Closed Won'){
  12.  
  13. Onboarding__c b = new Onboarding__c (); //instantiate the object to put values for future record
  14.  
  15. // now map opportunity fields to new vehicle object that is being created with this opportunity
  16.  
  17. b.Name = o.Name; // and so on so forth untill you map all the fields.
  18. b.Account__c = o.AccountId;
  19. //Monthly_Transactions__c
  20. //Current_Software_Platform__c
  21. //Operating_States__c
  22. //Underwriters__c
  23. //Number_of_employees__c
  24. //Pains__c
  25. //LeadSource
  26.  
  27. //**Next Step = "Send intro email"
  28.  
  29.  
  30. //once done, you need to add this new object to the list that would be later inserted.
  31. //don't worry about the details for now
  32.  
  33. onboardingToInsert.add(b);
  34.  
  35.  
  36. }//end if
  37.  
  38. }//end for o
  39.  
  40. //once loop is done, you need to insert new records in SF
  41. // dml operations might cause an error, so you need to catch it with try/catch block.
  42. try {
  43. insert OnboardingToInsert;
  44. } catch (system.Dmlexception e) {
  45. system.debug (e);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement