You need to sign in to do that
Don't have an account?
chaitanya babu ediga
REST bulk delete
Hi,
I'm novice to coding and explicitely REST. Is there a way to delete a list of records using REST API. I see bulk insert and update is possible. But there is no proper info on bulk delete. Any help would be appreciated.
Thanks in Advance!
I'm novice to coding and explicitely REST. Is there a way to delete a list of records using REST API. I see bulk insert and update is possible. But there is no proper info on bulk delete. Any help would be appreciated.
Thanks in Advance!
Execute batch via Execute Anonymous Window in Developer Console,
You may or may not find some syntex error or would have to change few minor things in above code targeting your own specific requirements, but this can be one of the approach. It's deletes in batches...
Hope this helps!
All Answers
@RestResource(urlMapping='/QLIDelete/*')
global with sharing class RESTQLIDelCon {
@HttpDelete
global static String deleteQLI() {
Id QuoteId = RestContext.request.params.get('Id');
//System.debug('RestContext.request.params'+ RestContext);
System.debug('Id======>' + QuoteId);
Quote DelQuote = [ Select ID from Quote where Id = :QuoteId];
List<QuoteLineItem> DelQLI= [SELECT Id, LineNumber from QuoteLineItem WHERE QuoteId =: DelQuote.Id];
if(!DelQLI.isEmpty()){
delete DelQLI;
return 'Quote Line Items are deleted';
}
else{
return 'Quote Line Items are not deleted due to some issues';
}
}
}
Execute batch via Execute Anonymous Window in Developer Console,
You may or may not find some syntex error or would have to change few minor things in above code targeting your own specific requirements, but this can be one of the approach. It's deletes in batches...
Hope this helps!
@RestResource(urlMapping='/QLIDelete/*')
global with sharing class RESTQLIDelCon {
@HttpDelete
global static String deleteQLI() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String QuoteId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
//Id QuoteId = RestContext.request.params.get('Id');
System.debug('Id======>' + QuoteId);
Quote DelQuote = New Quote();
try{
DelQuote = [ Select ID from Quote where PR_Number__c = :QuoteId];
List<QuoteLineItem> DelQLI= new List<QuoteLineItem>();
if(DelQuote!=NULL)
DelQLI = [SELECT Id, LineNumber from QuoteLineItem WHERE QuoteId =: DelQuote.Id];
delete DelQLI;
return 'Quote Line Items are deleted';
}catch (exception e) {
res.responseBody = Blob.valueOf(e.getMessage());
res.statusCode=400;
return 'Error';
}
}
}