You need to sign in to do that
Don't have an account?
karthik 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:
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:
try { 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.Name=whitepaper.Name; ObjWhitePaper.Document_Name__c=whitepaper.DocumentName; ObjWhitePaper.White_Paper_Id__c=whitepaper.WhitePaperId; 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:
@isTest public class CreateNewWhitePaperTest { static testmethod void TestCreateNewWhitePaper() { RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = 'https://offerboard--dev1.cs17.my.salesforce.com/services/apexrest/CreateWhitePaper'; 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 :
http://salesforce.stackexchange.com/questions/24984/test-class-rest-webservice-parameters
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 https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm