+ 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:
@HTTPDelete 
 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.setMethod('DELETE');
       
          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
          req.setEndpoint('https://ap2.salesforce.com/services/apexrest/AccountRest');  
           
          HttpResponse res = h.send(req); // JSON string is generated at this point
 system.debug('---res.getBody()--'+res.getBody());

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

Thanks
pooja
 
Thomas.SmithThomas.Smith
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.

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

https://www.sfdc-lightning.com/2019/01/salesforce-rest-api-integration-to-delete-a-record.html