You need to sign in to do that
Don't have an account?
Nihon Taisai
DELETE a record by REST API without @HttpDelete
0down votefavorite
I need to make integration between Org1 and Org2. We created a callout POST. When we create an object in Org1, we also create an object in Org2. POST work. All is Ok. Now I need also delete an object in Org2, if External Id in this obj == Id in obj from Org1.
Something like that:
I try to delete a record from another org, but I don't know, how to write it right. My Delete callout:
How can I fix it?
I need to make integration between Org1 and Org2. We created a callout POST. When we create an object in Org1, we also create an object in Org2. POST work. All is Ok. Now I need also delete an object in Org2, if External Id in this obj == Id in obj from Org1.
Something like that:
If(org2Object.ExternalId == org1Object.Id){ Delete org2Object; }
I try to delete a record from another org, but I don't know, how to write it right. My Delete callout:
private static Position__c pos = [SELECT Id, Name, Location__c, Job_Description__c, Salary_Range__c, Skills_Required__c, Education__c, Hiring_Manager__r.Name, Email__c, Phone__c, Status__c FROM Position__c WHERE Name = 'Title22']; public static String getRequestBody(){ Settings__c settings = [SELECT ConsumerKey__c, ClientSecret__c, Username__c, Password__c, SecurityToken__c FROM Settings__c WHERE Name = 'OurSettings']; String consumerKey = settings.ConsumerKey__c; String consumerSecret = settings.ClientSecret__c; String username = settings.Username__c; String password = settings.Password__c + settings.SecurityToken__c; String request = 'grant_type=password&client_id=' + consumerKey +'&client_secret=' + consumerSecret + '&username=' + username + '&password='+password; return request; } public static void deleteCalloutResponseContents(Id ourId){ Http ourHttp = new Http(); HttpRequest request = httpRequest('DELETE'); HttpResponse response = ourHttp.send(request); OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(response.getbody(), OAuth2.class); if(objAuthenticationInfo.ACCESS_TOKEN != null){ pos.Id = ourId; HttpRequest finalRequest = new HttpRequest(); String jsonstr='{"Position_ID__c":"'+ ourId +'"}'; finalRequest.setHeader('Authorization','Bearer '+ objAuthenticationInfo.ACCESS_TOKEN); finalRequest.setHeader('Content-Type','application/json'); finalRequest.setHeader('accept','application/json'); finalRequest.setBody(jsonstr); finalRequest.setMethod('DELETE'); request.setEndpoint(System.Label.Job_Advertisement_URL + '/services/data/v43.0/sobjects/Job_Advertisement__c/ourId'); response = ourHttp.send(finalRequest); System.debug('RESPONSE BODY: ' + response.getBody()); } } public class OAuth2{ public String ACCESS_TOKEN{get;set;} }
How can I fix it?
Hope this helps.
https://www.sfdc-lightning.com/2019/01/salesforce-rest-api-integration-to-delete-a-record.html