• SAURABH SRIVASTAVA 76
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi Experts,
I have created a simple RestResource class having GET, POST and DELETE methods.
I am tried to test them from both Workbench and from Soap UI (with aOuth 2.0 authentication)
All 3 services are working perfect from Workbench but DELETE is not working from Soap UI.
I ket logs and found that Soap UI is calling GET service even though I selected DELETE.

Attached Class snippet:
@RestResource(urlMapping='/api/Account/*')
global with sharing class MyFirstRestAPIClass
{
    @HttpGet
    global static Map<String,Account> doGet() 
    {
        Map<String,Account> MapResult = new Map<String,Account>();
        RestRequest req = RestContext.request;
        System.debug('Req: '+req);
        RestResponse res = RestContext.response;
      //  System.debug('Res: '+res);
        String AccName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
      //  System.debug('requestURI: '+req.requestURI);
      //  System.debug('lastIndexof: '+req.requestURI.lastIndexOf('/'));
      //  System.debug('AccName: '+AccName);
        List<Account> result = [SELECT Id, Name, Phone,Industry,AccountNumber, Website FROM Account WHERE name = :AccName ];
        for (Account a : result) {
            MapResult.put(a.id, a);
        }
        return MapResult;
    }

    @HttpDelete
    global static void doDelete() 
    {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        Account accToDelete = new Account();
        System.debug('iNSIDE DELETE Req: '+req);
        String AccName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        System.debug('AccName: '+AccName);
        List<Account> results = [SELECT Id FROM Account WHERE name = :AccName ];
        System.debug('result: '+results);
        delete results;       
        System.debug('AFTER DELETE result: '+results);
    }

    @HttpPost
    global static Account doPost(String name,String phone,String AccountNumber ) 
    {
        Account acc = new Account();
        acc.name= name;
        acc.phone=phone;
        acc.AccountNumber =AccountNumber ;
        insert acc;
        
        Account a = new Account();
        return a;
    }

}
Requesting DELETE method from Soap UILog in console after Delete request from Soap UI.
I have tried Postman also but it is having some different issue and unable to use that for any service.
Hi Experts,
I have created a simple RestResource class having GET, POST and DELETE methods.
I am tried to test them from both Workbench and from Soap UI (with aOuth 2.0 authentication)
All 3 services are working perfect from Workbench but DELETE is not working from Soap UI.
I ket logs and found that Soap UI is calling GET service even though I selected DELETE.

Attached Class snippet:
@RestResource(urlMapping='/api/Account/*')
global with sharing class MyFirstRestAPIClass
{
    @HttpGet
    global static Map<String,Account> doGet() 
    {
        Map<String,Account> MapResult = new Map<String,Account>();
        RestRequest req = RestContext.request;
        System.debug('Req: '+req);
        RestResponse res = RestContext.response;
      //  System.debug('Res: '+res);
        String AccName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
      //  System.debug('requestURI: '+req.requestURI);
      //  System.debug('lastIndexof: '+req.requestURI.lastIndexOf('/'));
      //  System.debug('AccName: '+AccName);
        List<Account> result = [SELECT Id, Name, Phone,Industry,AccountNumber, Website FROM Account WHERE name = :AccName ];
        for (Account a : result) {
            MapResult.put(a.id, a);
        }
        return MapResult;
    }

    @HttpDelete
    global static void doDelete() 
    {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        Account accToDelete = new Account();
        System.debug('iNSIDE DELETE Req: '+req);
        String AccName = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        System.debug('AccName: '+AccName);
        List<Account> results = [SELECT Id FROM Account WHERE name = :AccName ];
        System.debug('result: '+results);
        delete results;       
        System.debug('AFTER DELETE result: '+results);
    }

    @HttpPost
    global static Account doPost(String name,String phone,String AccountNumber ) 
    {
        Account acc = new Account();
        acc.name= name;
        acc.phone=phone;
        acc.AccountNumber =AccountNumber ;
        insert acc;
        
        Account a = new Account();
        return a;
    }

}
Requesting DELETE method from Soap UILog in console after Delete request from Soap UI.
I have tried Postman also but it is having some different issue and unable to use that for any service.
Has anyone experienced the Trails Completed count on their profile not increasing? I completed the Admin Beginner Trail last week and haven't seen my number of Trails Completed go from 0 to 1 - https://trailhead.salesforce.com/en/me/danny

(Read a bit about this popping up but I wasn't able to find anything recent or directly relevant)