0

I know I am a horrible coder. I tried below code snippet for REST Delete. But the Rest context returning me a null instead of Id even though I passed an Id from Workbench Rest explorer. Here is my code:

@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';
    }
  }
}
  • The below is the URL, I tried from Workbench: /services/apexrest/QLIDelete?id=0Q0n0000000XY61ABC – chaitanyababu e Feb 20 '18 at 0:05
2

Apex maps are case sensitive. You are requesting the key 'Id', but the URL provides the parameter 'id'. That's why you're obtaining a null value.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.