+ Start a Discussion
Devanshu soodDevanshu sood 

I am trying to write the test class for the following code. Please help me out.How to provide value to variable in dopost method?

@RestResource(urlMapping='/Outboundcall')
global class Outboundcall {

   @HttpPost
   global static String doPost() {
    
            string tonumber;
            string Fromnumber;
            string CallerName;
            string callSid;
            string Direction;
            string Callstatus;
            string outboundcallid;
            string res;
            string nondigits;
            string ext;
            
   RestRequest req = RestContext.request;
       system.debug(Callstatus);
   if(Callstatus =='initiated')
   { 
       tonumber=req.params.get('To');
       Fromnumber=req.params.get('From');
       CallerName=req.params.get('CallerName');
       callSid=req.params.get('callSid');
       Direction=req.params.get('Direction');
       Callstatus=req.params.get('Callstatus');
        nondigits = '[^0-9]';   
           User Usr = [SELECT Phone,extension,Id FROM User WHERE Did_Number__c = : tonumber limit 1 ];
           system.debug('==='+Usr);
           if(Usr!=null) 
           {
               ext= '1'+usr.extension.replaceAll(nondigits,'');
           }
           
           
           List<outbound_call__c> outboundcall_insert= new List<outbound_call__c>(); 
           outbound_call__c obc= new outbound_call__c();
           obc.Name=tonumber;
           obc.tonumber__c=tonumber;
           obc.Name=Fromnumber;
            
           obc.callSid__c=callSid;
           obc.Direction__c=Direction;
           obc.Callstatus__c=Callstatus;
           
           outboundcall_insert.add(obc);
           insert outboundcall_insert; 
          outboundcallid=outboundcall_insert[0].id;
          
     }
   else if(Callstatus=='in-progress')
   {
     /* outbound_call__c ld = [SELECT Read_Status__c,Callstatus__c,Extension__c,Id,Fromnumber__c FROM Incoming_Calls__c WHERE Extension__c =: ext AND Read_Status__c=false limit 1];
      ld.Callstatus__c=Callstatus;
      system.debug('==='+ld); 
      //ld.Read_Status__c=true;
      update ld;*/
      
   }
   else if(Callstatus=='completed')
   {
   
   }
    else if(Callstatus=='rejected')
   {
    
   }
   else
   {
   
   } 
       res='<?xml version="1.0" encoding="UTF-8" ?><Response></Response>';    
        return res;
    }
}
Best Answer chosen by Devanshu sood
Devanshu soodDevanshu sood

never mind
there is some mistake in code ,I corrected it