Guest User

Untitled

a guest
Jan 23rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. @RestResource(urlMapping='/Cases/*')
  2.  
  3. @HttpPut
  4. global static ID upsertCase(String supplierId, String extUserId, String extFormId, String extFormType, String extFormName, String extUrl, String origin) {
  5.  
  6. System.debug('upsertCase Call');
  7.  
  8. list<RecordType> RecordTypeName = new List<RecordType>([SELECT Id FROM RecordType WHERE SObjectType = 'Case' and Name = 'ThirdPartyApp']);
  9. system.debug('recordTypeName : ' +RecordTypeName[0].Id);
  10.  
  11. list<Account> accountName = new List<Account>([select Id from account where extid__c = :supplierID]);
  12. system.debug('accountName : ' +accountName[0].Id);
  13.  
  14. List<Contact> contactName = new List<Contact>([select Id from contact where extuser_id__c = :extUserId]);
  15. system.debug('contactName : ' +contactName[0].id);
  16.  
  17. system.debug('###1st extFormId : ' +extFormId);
  18. list<Case> existingCase = new List<Case>([select Id from case where extform_id__c = :extFormId]);
  19. /*if(existingCase.isempty() ) {
  20. existingCase[0].Id = null;
  21. } else {
  22. existingCase[0].Id = null;
  23. }*/
  24. system.debug('###2nd ExistingCase : ' +existingCase[0].id);
  25.  
  26. Case thisCase = new Case(
  27. RecordTypeId = recordTypeName[0].Id,
  28. AccountId = accountName[0].Id,
  29. ContactId = contactName[0].Id,
  30. extForm_ID__C = extFormId, // Need to use this field to determine existing or new case
  31. Type = extFormType,
  32. Subject = extFormName,
  33. extURL__C = extUrl,
  34. extUser_ID__c = extUserId,
  35. Status = 'New',
  36. Priority = 'Medium',
  37. Origin = origin,
  38. //Id = null);
  39. Id = existingCase[0].id);
  40. // Match case by Id, if present.
  41. // Otherwise, create new case.
  42. upsert thisCase;
  43. // Return the case ID.
  44. return thisCase.Id;
  45. }
Add Comment
Please, Sign In to add comment