Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. @RestResource(urlMapping='/Order/*')
  2. global with sharing class OrderWebServicesV2 {
  3.  
  4. private class OrderWrapper {
  5. Account account;
  6. list<ContactWrapper> contacts;
  7. }
  8.  
  9. private class ContactWrapper {
  10. Contact contact;
  11. list<Customer__c> customers;
  12. }
  13.  
  14. @HttpPost
  15. global static String doPost() {
  16.  
  17. OrderWrapper container = (OrderWrapper)System.JSON.deserialize(
  18. RestContext.request.requestBody.tostring(),
  19. OrderWrapper.class);
  20.  
  21. Account acc = container.account;
  22. upsert acc MyExternalId__c;
  23.  
  24. list<Contact> contactsToInsert = new list <Contact>();
  25. for (ContactWrapper wcon :container.contacts) {
  26. wcon.contact.accountId = acc.id;
  27. contactsToInsert.add(wcon.contact);
  28. }
  29. upsert contactsToInsert;
  30.  
  31. //now wrapper list contains contact ids
  32. list<Customer__c> customersToInsert = new list <Customer__c>();
  33. for (ContactWrapper wcon :container.contacts) {
  34. for (Customer__c customer :wcon.customers) {
  35. customer.Contact__c = wcon.contact.id;
  36. customersToInsert.add(customer);
  37. }
  38. }
  39. upsert customersToInsert;
  40. return acc.id;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement