• Daniel Shane
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi everyone, can someonehelp how to write testclass for the below class

@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
    //which is used to get the records or query the records
    global static Account doget(){
        //intilaise the object
       Account a=new Account();
        //get the req parameters in map
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id');
        //query the records
        a=[select id ,name from Account where id=:accid];
        return a;
    }
    @HttpDelete
    global static Account doDelete(){
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
        delete result;
        return result;
    }
   @Httppost
    //post method is used to create the record
    global static Account docreate(string name){
        Account a = new Account(name=name);
        insert a;
        return a;
    }
     @Httpput
    global static Account doupdate(string name){
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id'); 
        Account a = new Account(name=name, id=accid);
        update a;
        return a;
    }
}

Thanks in Advance
  • August 17, 2021
  • Like
  • 1