Advertisement
martyychang

Create a Case and Opportunity Related to an Account

Feb 7th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. // Retrieve the Account record for which you want to create related
  2. // Cases and Opportunities
  3.  
  4. Account ram = [SELECT Id, Name FROM Account WHERE Name = 'Ram'];
  5.  
  6. // Create a related Case. Note that there is a more efficient way to
  7. // instantiate the Case object than what's shown below. The steps shown
  8. // below is the "long" but more familiar way for new developers.
  9.  
  10. Case ramCase = new Case();
  11. ramCase.AccountId = ram.Id;  // Set the relationship to the Account
  12. ramCase.Subject = 'Sales Cloud Best Practices';
  13.  
  14. insert ramCase;
  15.  
  16. // Create a related Opportunity. Depending on your org's configuration,
  17. // you may need to specify values for other required fields.
  18.  
  19. Opportunity ramOpportunity = new Opportunity();
  20. ramOpportunity.AccountId = ram.Id;  // Relate the relationship to the Account
  21. ramOpportunity.Name = 'Sales Cloud Implementation';
  22. ramOpportunity.StageName = 'Prospecting';
  23. ramOpportunity.CloseDate = Date.today();
  24.  
  25. insert ramOpportunity;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement