function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthik Jonnalagaddakarthik Jonnalagadda 

Not getting look up value

Hello all,

I wrote a web service to insert  values into object. Its working fine. but when I am tring to call it from Test method I am not able to get the lookup values The query returnig zero values. 

My Web service:
{         RestRequest req = RestContext.request;
         String bdy = req.requestBody.toString(); 
         new_whitepaper_registration whitepaper = (new_whitepaper_registration)JSON.Deserialize(bdy,new_whitepaper_registration.class);
         White_Papers__c ObjWhitePaper =New White_Papers__c(); 
         ObjWhitePaper.Lead_Name__c=[select ID from Lead where Name=:whitepaper.LeadName Limit 1].ID;   
 		insert ObjWhitePaper;	
   return new ReturnClass('True');
catch(Exception ex)
system.debug('ERROR: '+ex.getMessage()+ ' '+ex.getStackTraceString());   
 return new ReturnClass('false');
My Test Class: 
public class CreateNewWhitePaperTest {
static testmethod void TestCreateNewWhitePaper()
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        req.requestURI = '';  
      req.httpMethod = 'POST';
        req.requestBody=Blob.valueof('{"Name":"Test White Paper","WhitePaperId":"123","DocumentName":"Demo Doc","LeadName":"Punam Sharma"}');
        RestContext.request = req;
       RestContext.response = res;
        CreateWhitePaper.ReturnClass results = CreateWhitePaper.NewWhitePaper();      
   		 System.assertEquals('True', results.success);

Check if this link resolve your issue :
Shailendra Singh ParmarShailendra Singh Parmar
Hi Karthik,
I think, you need to create mock class to write test class because WS will bot be invoked from test class instead we write mock class and set it in test context. Not sure if you have already gone throw this link
karthik Jonnalagaddakarthik Jonnalagadda
Thanks for quick reply. I have similar classes for other objects, Those are working fine but issue with this class.