+ Start a Discussion
GYAN ANDRUSGYAN 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
Nagendra Prasad ChNagendra Prasad Ch
You have commented the line  res.errorCode = peer.Constants.INVALID_INPUT, still r u facing same error?
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?
 
GYAN ANDRUSGYAN ANDRUS
@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 ='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);
    }    
    
    
    
    

}
Nagendra Prasad ChNagendra Prasad Ch
statuscode  is declared as an Integer in Response  class.
  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.
 
GYAN ANDRUSGYAN ANDRUS
It is saved ,But when i try to see  in POSTMAN,It showing Invalid Format.
    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
Nagendra Prasad ChNagendra Prasad Ch
Try this code,
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

 
@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');
		String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        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;
        
    }
}
}

 
GYAN ANDRUSGYAN ANDRUS
Thanks a lot....But Only i need the PBSI__PBSI_Item__c  records as JSON format..I dont want the Account ID,I have given the URL with account ID ,,NOt Showing


Regards.Gyan
GYAN ANDRUSGYAN ANDRUS
You have attempted to reach a URL that no longer exists on salesforce.com.ERROR in POSTMAN,,Please help
Nagendra Prasad ChNagendra Prasad Ch
Relace first line with this, it might help
@RestResource(urlMapping='/WSItemMasterProductFacilities/*')
@RestResource(urlMapping='/WSItemMasterProductFacilities/*')

 
GYAN ANDRUSGYAN ANDRUS
NOt WorkingUser-added image
Nagendra Prasad ChNagendra Prasad Ch
This documentation might help you. Go through all topics related to REST in that left side menu.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm