+ Start a Discussion
pooja biswaspooja biswas 

@HttpDelete question

Hi friends
This is an urgent requirement, kindly help.
I have two different salesforce accounts  and I am trying to delete records based on criteria using rest api annotation @HttpDelete

The code in destination is:
 webservice static string DeleteAccounts()  
    Account a=[select Id from account where Name LIKE :'%TVS Electronics%'];
    return a.ID;
The code in source is:

          Http h = new Http();
          HttpRequest req = new HttpRequest();
          req.setHeader('Authorization','Bearer '+Helper.GetAccessToken().access_token);
          req.setHeader('Content-Type','application/json; charset=UTF-8');
          //call the rest resource URL and this url needs to be registered in remote settings
          HttpResponse res = h.send(req); // JSON string is generated at this point

In res.getBody() , I am getting the ID of the record which was passed from source
Now how do I pass this ID back to source indicating that this record is to be deleted.

I hope I am clear

Hey Pooja,

Can you confirm why you are returning this Id back from the Rest Resource?

You are using the @HttpDelete (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_http_delete.htm) annotation which is called when a HTTP Delete request is sent. I am also certain you should be performing a DELETE DML (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_section.htm) operation rather than returning the ID. 

I may have misunderstood your objective.

Thomas Smith.
farukh sk hdfarukh sk hd
Here integration is performed for deleting record from salesforce using rest api.
Hope this helps.