Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestResource(urlMapping='/Cases/*')
- @HttpPut
- global static ID upsertCase(String supplierId, String extUserId, String extFormId, String extFormType, String extFormName, String extUrl, String origin) {
- System.debug('upsertCase Call');
- list<RecordType> RecordTypeName = new List<RecordType>([SELECT Id FROM RecordType WHERE SObjectType = 'Case' and Name = 'ThirdPartyApp']);
- system.debug('recordTypeName : ' +RecordTypeName[0].Id);
- list<Account> accountName = new List<Account>([select Id from account where extid__c = :supplierID]);
- system.debug('accountName : ' +accountName[0].Id);
- List<Contact> contactName = new List<Contact>([select Id from contact where extuser_id__c = :extUserId]);
- system.debug('contactName : ' +contactName[0].id);
- system.debug('###1st extFormId : ' +extFormId);
- list<Case> existingCase = new List<Case>([select Id from case where extform_id__c = :extFormId]);
- /*if(existingCase.isempty() ) {
- existingCase[0].Id = null;
- } else {
- existingCase[0].Id = null;
- }*/
- system.debug('###2nd ExistingCase : ' +existingCase[0].id);
- Case thisCase = new Case(
- RecordTypeId = recordTypeName[0].Id,
- AccountId = accountName[0].Id,
- ContactId = contactName[0].Id,
- extForm_ID__C = extFormId, // Need to use this field to determine existing or new case
- Type = extFormType,
- Subject = extFormName,
- extURL__C = extUrl,
- extUser_ID__c = extUserId,
- Status = 'New',
- Priority = 'Medium',
- Origin = origin,
- //Id = null);
- Id = existingCase[0].id);
- // Match case by Id, if present.
- // Otherwise, create new case.
- upsert thisCase;
- // Return the case ID.
- return thisCase.Id;
- }
Add Comment
Please, Sign In to add comment