You need to sign in to do that
Don't have an account?
Reshmi Smiju
Issues with Rest Resoucre.
Hi,
Below is my Rest Resource code to search Opportunities based on particlar Stage Name. But, when I tried to search in Workbench, I am getting the below error. Actually for any url, the error is same. Pls let me know, what is the issue with my code.
Below is my code :
@RestResource(urlMapping = '/Opp/Search/*')
global with sharing class SearchOppty{
@HttpGet
global static opp_Wrap searchopp(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
opp_Wrap response = new opp_Wrap();
String text = req.requestURI.Substring(req.requestURI.lastIndexof('/')+1);
if(doSearch(text))
SearchOppByStageName(req,res,response);
return response;
}
public static Boolean doSearch(String text){
if(text == 'StageName')
return true;
else
return false;
}
public static void SearchOppByStageName(RestRequest req, RestResponse res, Opp_Wrap response){
String finaltxt = req.params.get('StageName');
if(finaltxt == null && finaltxt == ''){
response.Status = 'Error';
response.Message ='Enter in correct format';
}
else{
List<Opportunity> opps = [select Name, CloseDate, Amount, StageName from Opportunity
where StageName =:finaltxt];
if(opps!= null && opps.size()>0){
response.opp = opps;
response.Status = 'Success';
response.Message = opps.size() + ' Opportunity';
}
else{
response.opp = null;
response.Status = 'Error';
response.Message = opps.size() + ' Opportunity';
}
}
}
global class opp_Wrap{
public List<Opportunity>opp;
public String Status;
public String Message;
public opp_Wrap(){}
}
}
Below is my Rest Resource code to search Opportunities based on particlar Stage Name. But, when I tried to search in Workbench, I am getting the below error. Actually for any url, the error is same. Pls let me know, what is the issue with my code.
Below is my code :
@RestResource(urlMapping = '/Opp/Search/*')
global with sharing class SearchOppty{
@HttpGet
global static opp_Wrap searchopp(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
opp_Wrap response = new opp_Wrap();
String text = req.requestURI.Substring(req.requestURI.lastIndexof('/')+1);
if(doSearch(text))
SearchOppByStageName(req,res,response);
return response;
}
public static Boolean doSearch(String text){
if(text == 'StageName')
return true;
else
return false;
}
public static void SearchOppByStageName(RestRequest req, RestResponse res, Opp_Wrap response){
String finaltxt = req.params.get('StageName');
if(finaltxt == null && finaltxt == ''){
response.Status = 'Error';
response.Message ='Enter in correct format';
}
else{
List<Opportunity> opps = [select Name, CloseDate, Amount, StageName from Opportunity
where StageName =:finaltxt];
if(opps!= null && opps.size()>0){
response.opp = opps;
response.Status = 'Success';
response.Message = opps.size() + ' Opportunity';
}
else{
response.opp = null;
response.Status = 'Error';
response.Message = opps.size() + ' Opportunity';
}
}
}
global class opp_Wrap{
public List<Opportunity>opp;
public String Status;
public String Message;
public opp_Wrap(){}
}
}
Hi,
try to modifie your code like below and verify by below rest call
/services/apexrest/Opp/Search?StageName=Qulification
All Answers
Hi,
try to modifie your code like below and verify by below rest call
/services/apexrest/Opp/Search?StageName=Qulification