You need to sign in to do that
Don't have an account?
GYAN ANDRUS
Hi Anyone please help me out of this error
@RestResource(urlMapping='/WSItemMasterProductFacilities')
global class WSItemMasterProductFacilities {
@HttpPost
global static Response ItemMasterProductFacilities() {
RestRequest req = RestContext.request;
RestResponse restRes = RestContext.response;
Response res = new Response('ItemMasterProductFacilities');
//Headers from request
String accountId = req.headers.get('Account-ID');
System.debug('accountId in WSBorrowerReports = '+accountId);
if(accountId == null)
{
//res.errorCode = peer.Constants.INVALID_INPUT;
res.status = peer.Constants.ERROR;
res.message = 'ACCOUNT_ID_NOT_PRESENT_IN_HEADER';
restRes.statuscode = peer.Constants.HTTP_BAD_REQUEST;
return res;
}
try
{
String j;
//String NameValue = req.params.get('name');
List <PBSI__PBSI_Item__c> itemMasterList = new List<PBSI__PBSI_Item__c>();
PBSI__PBSI_Item__c loanDisbursalTrans;
WrapperItemMasterparticipatedList ItemTrans = new WrapperItemMasterparticipatedList();
List<WrapperItemMasterparticipatedList> ItemTransData = new List<WrapperItemMasterparticipatedList>();
itemMasterList = [Select id,Name from PBSI__PBSI_Item__c];
for(j=0;j<itemMasterList.size();j++)
{
ItemTrans = new WrapperItemMasterparticipatedList();
loanDisbursalTrans = itemMasterList.get(j);
ItemTrans.entity_id = loanDisbursalTrans.name;
ItemTransData.add(ItemTrans);
}
//Sending Response
res.ItemTransData = ItemTransData;
// restRes.statuscode = peer.Constants.HTTP_OK;
res.status = peer.Constants.SUCCESS;
return res;
}
catch (Exception e) {
System.debug('Exception e is ='+e);
res.errorCode = 'Line number= '+e.getLineNumber()+' Message is= ' +e.getmessage();
res.status = peer.Constants.ERROR;
res.message = 'Internal Exeption Occurred';
restRes.statuscode = peer.Constants.HTTP_INTERNAL_ERROR;
return res;
}
}
}
ERROR:Variable does not exist: peer.Constants.INVALID_INPUT
global class WSItemMasterProductFacilities {
@HttpPost
global static Response ItemMasterProductFacilities() {
RestRequest req = RestContext.request;
RestResponse restRes = RestContext.response;
Response res = new Response('ItemMasterProductFacilities');
//Headers from request
String accountId = req.headers.get('Account-ID');
System.debug('accountId in WSBorrowerReports = '+accountId);
if(accountId == null)
{
//res.errorCode = peer.Constants.INVALID_INPUT;
res.status = peer.Constants.ERROR;
res.message = 'ACCOUNT_ID_NOT_PRESENT_IN_HEADER';
restRes.statuscode = peer.Constants.HTTP_BAD_REQUEST;
return res;
}
try
{
String j;
//String NameValue = req.params.get('name');
List <PBSI__PBSI_Item__c> itemMasterList = new List<PBSI__PBSI_Item__c>();
PBSI__PBSI_Item__c loanDisbursalTrans;
WrapperItemMasterparticipatedList ItemTrans = new WrapperItemMasterparticipatedList();
List<WrapperItemMasterparticipatedList> ItemTransData = new List<WrapperItemMasterparticipatedList>();
itemMasterList = [Select id,Name from PBSI__PBSI_Item__c];
for(j=0;j<itemMasterList.size();j++)
{
ItemTrans = new WrapperItemMasterparticipatedList();
loanDisbursalTrans = itemMasterList.get(j);
ItemTrans.entity_id = loanDisbursalTrans.name;
ItemTransData.add(ItemTrans);
}
//Sending Response
res.ItemTransData = ItemTransData;
// restRes.statuscode = peer.Constants.HTTP_OK;
res.status = peer.Constants.SUCCESS;
return res;
}
catch (Exception e) {
System.debug('Exception e is ='+e);
res.errorCode = 'Line number= '+e.getLineNumber()+' Message is= ' +e.getmessage();
res.status = peer.Constants.ERROR;
res.message = 'Internal Exeption Occurred';
restRes.statuscode = peer.Constants.HTTP_INTERNAL_ERROR;
return res;
}
}
}
ERROR:Variable does not exist: peer.Constants.INVALID_INPUT
Error is straight forward, in peer.Constants class there is no variable called 'INVALID_INPUT'.check whether ur using same variable defined there or not?
global class WSItemMasterProductFacilities {
@HttpPost
global static Response ItemMasterProductFacilities() {
RestRequest req = RestContext.request;
RestResponse restRes = RestContext.response;
Response res = new Response('ItemMasterProductFacilities');
//Headers from request
String accountId = req.headers.get('Account-ID');
System.debug('accountId in WSBorrowerReports = '+accountId);
if(accountId == null)
{
res.errorCode ='INVALID_INPUT';
res.status = 'ERROR';
res.message = 'ACCOUNT_ID_NOT_PRESENT_IN_HEADER';
res.statuscode = 'HTTP_BAD_REQUEST';
return res;
}
try
{
integer j;
//String NameValue = req.params.get('name');
List <PBSI__PBSI_Item__c> itemMasterList = new List<PBSI__PBSI_Item__c>();
PBSI__PBSI_Item__c loanDisbursalTrans;
WrapperItemMasterparticipatedList ItemTrans = new WrapperItemMasterparticipatedList();
List<WrapperItemMasterparticipatedList> ItemTransData = new List<WrapperItemMasterparticipatedList>();
itemMasterList = [Select id,Name from PBSI__PBSI_Item__c];
for(j=0;j<itemMasterList.size();j++)
{
ItemTrans = new WrapperItemMasterparticipatedList();
loanDisbursalTrans = itemMasterList.get(j);
ItemTrans.entity_id = loanDisbursalTrans.name;
ItemTransData.add(ItemTrans);
}
//Sending Response
res.ItemTransData = ItemTransData;
restRes.statuscode = 'HTTP_OK';
res.status = 'SUCCESS';
return res;
}
catch (Exception e) {
System.debug('Exception e is ='+e);
res.errorCode = 'Line number= '+e.getLineNumber()+' Message is= ' +e.getmessage();
res.status = 'ERROR';
res.message = 'Internal Exeption Occurred';
restRes.statuscode = 'HTTP_INTERNAL_ERROR';
return res;
}
}
}
Illegal assignment from String to Integer
RESPONSE CLASS:
global class Response {
public List <WrapperItemMasterparticipatedList> ItemTransData { get; set;}
// public List<WrapperInvestorAllFacilities> investorAllFacilitiesData { get; set;}
public String message {get;set;}
public String errorCode {get; set;}
public String status {get; set;}
public integer statuscode {get; set;}
public Response(){
status = '';
message = '';
errorCode = '';
}
public Response(String reason){
if(reason == 'ItemMasterProductFacilities')
{
ItemTransData = new List<WrapperItemMasterparticipatedList>();
}
}
global static boolean isNotNullOrEmpty(string str)
{
return str!=null || !String.isBlank(str);
}
}
public integer statuscode {get; set;}
But, in WSItemMasterProductFacilities class ur assigning Strings to Statuscode (integer)
res.statuscode = 'HTTP_BAD_REQUEST';
restRes.statuscode = 'HTTP_OK';
restRes.statuscode = 'HTTP_INTERNAL_ERROR';
That's why this error.
Solution is,
Make statuscode also a string in Response class.
public string statuscode {get; set;}
Please let me know if it will work.
My remote Site Setting URL:https://aci--uat.cs23.my.salesforce.com,I have given the link in POSTMAN Like
https://aci--uat.cs23.my.salesforce.com/apexrest/WSItemMasterProductFacilities-ERROR
Can u please ,HOw to check that,It is not showing JSON format
Instead of String accountId = req.headers.get('Account-ID'); try String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Pass your AccountId in URL,
https://aci--uat.cs23.my.salesforce.com/apexrest/WSItemMasterProductFacilities/AccountId
Replace AccountId in above URL with ur Account Id
Ex : https://aci--uat.cs23.my.salesforce.com/apexrest/WSItemMasterProductFacilities/001eArhks5gns2gAAH
Regards.Gyan
@RestResource(urlMapping='/WSItemMasterProductFacilities/*')
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm