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
miteshsuramiteshsura 

writing test class for a web service method

hello all,

 

I have a APEX class, with a webservice

 

 

global class ProductAdminWebService { 
...
...
   webservice static string goLive(string recordId, string status, string productRegion){ 
   ...
   ...
   }
 }

 

 

The only purpose why its a web service, so I can call from my custom button on VF page with a page refresh. It does not make any call outs. 

 

The webservice has a SOSL (NOT SOQL) querry and returns result when called from my custom button on VF page but returns nothing when called from my test method. Am I missing anything here? Below is the SOSL query:

 

 

 

List<List<SObject>> searchList;

searchList = [FIND :productRegion IN ALL FIELDS
    RETURNING 
                                                Product_Administration__c (id, Description__c, Product__c, Product_Region__c, AP_Price__c, Direct_Price__c, Dist_Price__c, LA_Price__c, Standard_Price__c, Schedule_Date__c WHERE Id= :recordId), 
                                                Service_Administration__c (id, Description__c, Product__c, Product_Region__c, AP_Price__c, Direct_Price__c, Dist_Price__c, LA_Price__c, Standard_Price__c WHERE Product_Administration__c= :recordId LIMIT 7)
                                              LIMIT 8];

 

 

 

This is urgent, as I need to deploy to production asap. Please help. 

sham_1sham_1

SOSL doesn't work in test methods.

however you can use methods in test class to force the search results to be returned

 

eg straight from the docs

Id [] fixedSearchResults= new Id[1];
fixedSearchResults[0] = '001x0000003G89h';
Test.setFixedSearchResults(fixedSearchResults);
List<List<SObject>> searchList = [FIND 'test'
IN ALL FIELDS RETURNING
Account(id, name WHERE name = 'test' LIMIT 1)];

 

 

miteshsuramiteshsura

After hard day looking at it, I fig'd yday night.. one thing I am trying now is, in my SOSL, I am serching in multiple objects, how can I add Id for additional object in that test eg you provided ?? 

 

Does it make sense?