+ Start a Discussion
Iqra TechIqra Tech 

I need to add sobject values in my wrapper class

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 StandNo,String BannerName)
        {
            this.EventName =EventName;
            this.RecordId =RecordId;
            this.RecordName =RecordName;
            this.RecordStage=RecordStage;
            this.StandNo=StandNo;
            this.BannerName=BannerName;
            
        }
    }

i am having this wrapper class now i need to add my sObject values in this wrapper class 

 

public class Post_Records {
    
    Public static void Insert_Records(){
   
        List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
                                                         from Opportunity_Prod_Batch_Record__c  ];
        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);


       
 }

 

now i need to add sobejct values in my wrapper class please help me it is urgent

Best Answer chosen by Iqra Tech
Raj VakatiRaj Vakati
You need to do like this
public class Post_Records {
    
    Public static void Insert_Records(){
   
        List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
                                                         from Opportunity_Prod_Batch_Record__c  ];
        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);

List<OppWrapper> oppWrapper = new List<OppWrapper>() ;
For(sObject s : sc){
Opportunity o = (Opportunity)s ; 
OppWrapper op = new OppWrapper(o.Name,o.Id,o.Name,o.StageName,o.Stand_no__c,o.Banner_Name__c);
oppWrapper.add(op);
}

       
 }

 

All Answers

Raj VakatiRaj Vakati
You need to do like this
public class Post_Records {
    
    Public static void Insert_Records(){
   
        List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
                                                         from Opportunity_Prod_Batch_Record__c  ];
        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);

List<OppWrapper> oppWrapper = new List<OppWrapper>() ;
For(sObject s : sc){
Opportunity o = (Opportunity)s ; 
OppWrapper op = new OppWrapper(o.Name,o.Id,o.Name,o.StageName,o.Stand_no__c,o.Banner_Name__c);
oppWrapper.add(op);
}

       
 }

 
This was selected as the best answer
Iqra TechIqra Tech
@Raj Vakati thanks for the qucik reply 
actually i need to POST the records in THird party api currently i am able to fecth the all the  records which i wants but stcuk in posting the records 
can you please help me....
Raj VakatiRaj Vakati
You can conervt the wrapper class as json and sent to  external  system 
 
//create lineItemRequest
List<orderLineItemRequestResource> linteItemList = new List<orderLineItemRequestResource>();
orderLineItemRequestResource linteItem = new orderLineItemRequestResource();
lineItem.quantity = 'xxx';
lineItem.unitPrice = 'xxx';
lineItem.description = 'xxx';
lineItem.productCode = 'xxx';
lineItem.externalKey = 'xxx';
linteItemList.add(lineItem);


//order request resource object
orderRequestResource objOrderRequest = new orderRequestResource();
objOrderRequest.accountUNumber = '';
objOrderRequest.contractNumber = '';
objOrderRequest.status = '';
objOrderRequest.externalKey = '';
objOrderRequest.orderStartDate = '';
objOrderRequest.priceBookName = '';
/********because it is expecting a list of*********************/
/********orderLineItemRequestResource we will first create******/
list before assigning here.
objOrderRequest.orderItems = linteItemList;


//Final object which is required for call out
requestResource rest = new requestResource();
rest.order = objOrderRequest;
// Convert to JSON format
String finalJSON = System.json.serialize(rest);

 
Iqra TechIqra Tech


@Raj Vakati

many thanks to you now i am able to run class sucessfully using your provided method and post the data sucesfully in third party api
now i need convert this class in batch class can it be possible?

Iqra TechIqra Tech
@Raj Vakati
sir u there i need one more favour from you
Raj VakatiRaj Vakati
tell me what is the issue
Iqra TechIqra Tech

@Raj Vakati
sir plese chehk this post 

https://developer.salesforce.com/forums/ForumsMain?id=9062I000000g9UYQAY#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=OPENQUESTIONS&id=9062I000000g9boQAA
Iqra TechIqra Tech
@Raj Vakati sir u der?
Raj VakatiRaj Vakati
Sure .. Let me check the above thread