+ Start a Discussion
Iqra TechIqra Tech 

Constructor not defined: [Post_Records.OppWrapper].<Constructor>(OpportunityLineItem)

I am getting this error on this http callout class
Error:-
Constructor not defined: [Post_Records.OppWrapper].<Constructor>(OpportunityLineItem
)


public class Post_Records {
    
    Public static void Insert_Records()
    {           
      List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
      LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c  from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
      String query= 'select ID,'+LstFlrmapping[0].Edition__c+','+LstFlrmapping[0].Opportunity__c+','+LstFlrmapping[0].Opportunity_Id__c+','+LstFlrmapping[0].Stage__c+','+LstFlrmapping[0].Banner_Name__c +','+LstFlrmapping[0].Stand_no__c +' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';

      String Edition=LstFlrmapping[0].Edition__c;
      String Opportunity=LstFlrmapping[0].Opportunity__c;
      String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
      String Objects=LstFlrmapping[0].Object__c;
      String stage=LstFlrmapping[0].Stage__c;
      String BannerName=LstFlrmapping[0].Banner_Name__c;
      String StandNo=LstFlrmapping[0].Stand_no__c;
      System.debug('Query formed----> '+query); 

     List<sObject> sc= Database.query(query);
     System.debug('All Records -->'+sc);
       
     List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
     for(sObject  s : sc) 
     {
       OpportunityLineItem o = (OpportunityLineItem)s ;
       //OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.P_Banner__c,o.Stand_Number_s__c);
       OppWrapper oppwrappervar=new OppWrapper(o);
       oppWrapperVarList.add(oppwrappervar);
     }
         system.debug('Tracking --->'+oppWrapperVarList);
        //system.debug('Chehking --->'+oppwrappervar);
        string jsonbody=Json.serialize(oppWrapperVarList);
        system.debug('Json body---->'+jsonbody);
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
            request.setTimeout(20000);
        //request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
        request.setEndpoint('http://sfdata.iqratechnology.com/api/data');

        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
     
        request.setBody(jsonbody);
        
       HttpResponse response = http.send(request);
        system.debug('Response body '+ response.getBody());
     if (response.getStatusCode() != 201) {
        System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
      } else {
    System.debug(response.getBody());
    }
        
        
    }
    
    public class OppWrapper
    {
        public String EventName {get;set;}
        public String RecordId {get;set;}
        public String RecordName {get;set;}
        public String RecordStage {get;set;}
        public String BannerName {get;set;}
        public String StandNo {get;set;}
        public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String BannerName,String StandNo)
        {
            this.EventName =EventName;
            this.RecordId =RecordId;
            this.RecordName =RecordName;
            this.RecordStage=RecordStage;
            this.BannerName=BannerName;
            this.StandNo=StandNo;
            
        }
    }
    
}
Raj VakatiRaj Vakati
Use this code


OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.P_Banner__c,o.Stand_Number_s__c);

 
public class Post_Records {
    
    Public static void Insert_Records()
    {           
      List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
      LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c  from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
      String query= 'select ID,'+LstFlrmapping[0].Edition__c+','+LstFlrmapping[0].Opportunity__c+','+LstFlrmapping[0].Opportunity_Id__c+','+LstFlrmapping[0].Stage__c+','+LstFlrmapping[0].Banner_Name__c +','+LstFlrmapping[0].Stand_no__c +' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';

      String Edition=LstFlrmapping[0].Edition__c;
      String Opportunity=LstFlrmapping[0].Opportunity__c;
      String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
      String Objects=LstFlrmapping[0].Object__c;
      String stage=LstFlrmapping[0].Stage__c;
      String BannerName=LstFlrmapping[0].Banner_Name__c;
      String StandNo=LstFlrmapping[0].Stand_no__c;
      System.debug('Query formed----> '+query); 

     List<sObject> sc= Database.query(query);
     System.debug('All Records -->'+sc);
       
     List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
     for(sObject  s : sc) 
     {
       OpportunityLineItem o = (OpportunityLineItem)s ;
       OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.P_Banner__c,o.Stand_Number_s__c);
       //OppWrapper oppwrappervar=new OppWrapper(o);
       oppWrapperVarList.add(oppwrappervar);
     }
         system.debug('Tracking --->'+oppWrapperVarList);
        //system.debug('Chehking --->'+oppwrappervar);
        string jsonbody=Json.serialize(oppWrapperVarList);
        system.debug('Json body---->'+jsonbody);
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
            request.setTimeout(20000);
        //request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
        request.setEndpoint('http://sfdata.iqratechnology.com/api/data');

        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
     
        request.setBody(jsonbody);
        
       HttpResponse response = http.send(request);
        system.debug('Response body '+ response.getBody());
     if (response.getStatusCode() != 201) {
        System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
      } else {
    System.debug(response.getBody());
    }
        
        
    }
    
    public class OppWrapper
    {
        public String EventName {get;set;}
        public String RecordId {get;set;}
        public String RecordName {get;set;}
        public String RecordStage {get;set;}
        public String BannerName {get;set;}
        public String StandNo {get;set;}
        public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String BannerName,String StandNo)
        {
            this.EventName =EventName;
            this.RecordId =RecordId;
            this.RecordName =RecordName;
            this.RecordStage=RecordStage;
            this.BannerName=BannerName;
            this.StandNo=StandNo;
            
        }
    }
    
}

 
Iqra TechIqra Tech
@Raj Vakati Yes it is working on that but i need when i am not selecvted any field on that time it gives  me this Error
Error:-
Line: 35, Column: 1
System.QueryException: unexpected token: 'null'

so the thing is i need to dynamically post the data in the api
Iqra TechIqra Tech
public class Post_API_Class {
    
    Public static void Insert_Records()
    {           
      List<Floor_Plan_Mapping__c> LstFlrmapping=new list< Floor_Plan_Mapping__c>();
      LstFlrmapping=[select Id, Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c  from Floor_Plan_Mapping__c order by createdDate DESC limit 1];
      
       String query= 'select ID,' ;
       if(LstFlrmapping[0].Edition__c!=null){
           query += LstFlrmapping[0].Edition__c+',' ; 
       }
       if(LstFlrmapping[0].Opportunity__c!=null){
           query += LstFlrmapping[0].Opportunity__c+',' ; 
       }
       if(LstFlrmapping[0].Opportunity_Id__c!=null){
           query += LstFlrmapping[0].Opportunity_Id__c+',' ; 
       }
       if(LstFlrmapping[0].Stage__c!=null){
           query += LstFlrmapping[0].Stage__c+',' ; 
       }
       if(LstFlrmapping[0].Banner_Name__c!=null){
           query += LstFlrmapping[0].Banner_Name__c+',' ; 
       }
       if(LstFlrmapping[0].Stand_no__c!=null){
           query += LstFlrmapping[0].Stand_no__c+',' ; 
       }
      
       
       query = query.removeEnd(',');
 
       query += ' from '+LstFlrmapping[0].Object__c+' where '+LstFlrmapping[0].Edition__c+' = \''+LstFlrmapping[0].Edition_Event_Name__c +'\'';
      
      

      

      String Edition=LstFlrmapping[0].Edition__c;
      String Opportunity=LstFlrmapping[0].Opportunity__c;
      String OpprtunityId=LstFlrmapping[0].Opportunity_Id__c;
      String Objects=LstFlrmapping[0].Object__c;
      String stage=LstFlrmapping[0].Stage__c;
      String BannerName=LstFlrmapping[0].Banner_Name__c;
      String StandNo=LstFlrmapping[0].Stand_no__c;
      System.debug('Query formed----> '+query); 

     List<sObject> sc= Database.query(query);
     System.debug('All Records -->'+sc);
       
     List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
     for(sObject  s : sc) 
     {
       
       OpportunityLineItem o = (OpportunityLineItem)s ;
         try
         {         
          OppWrapper oppwrappervar=new OppWrapper(o.P_Edition__c,o.P_Opportunity_ID__c,o.p_Opprotuny_name__c,o.P_Stage__c,o.P_Banner__c,o.Stand_Number_s__c);

       oppWrapperVarList.add(oppwrappervar);
         }catch(Exception ex)
         {
             System.debug('================'+ex.getMessage()+'======================'+ex);
         }
        
     }

        string jsonbody=Json.serialize(oppWrapperVarList);
        system.debug('Json body---->'+jsonbody);
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setTimeout(20000);
        //request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
        request.setEndpoint('http://sfdata.iqratechnology.com/api/data');

        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
     
        request.setBody(jsonbody);
        
       HttpResponse response = http.send(request);
        system.debug('Response body '+ response.getBody());
     if (response.getStatusCode() != 201) {
        System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
      } else {
    System.debug(response.getBody());
    }
        
        
    }
    
    public class OppWrapper
    {
        public String EventName {get;set;}
        public String RecordId {get;set;}
        public String RecordName {get;set;}
        public String RecordStage {get;set;}
        public String StandNo {get;set;}
         public String BannerName {get;set;}
        public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String BannerName,String StandNo)
        {
            this.EventName =EventName;
            this.RecordId =RecordId;
            this.RecordName =RecordName;
            this.RecordStage=RecordStage;
            this.StandNo=StandNo;
            this.BannerName=BannerName;
            
        }
    }
    
}

I am added dynamically query on that time it not showing this error
Error:- Line: 35, Column: 1
System.QueryException: unexpected token: 'null'

now if i am not selected any field on that time Posting data in API using wrapper class i am facing this errr: see this scrren shot

 
Iqra TechIqra Tech
@Raj Vakati sir u der??
Iqra TechIqra Tech
@Raj Vakati sir i need help can u please guide me