function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priyesh Misquith 12Priyesh Misquith 12 

creating wrapper class of seperate list and creating table in vf componet

 I want to Create a wrapper class and combine both list and populate in the table .

CustomObject1__c custom1 =[select id,Attn__c,Forwarder__c,Branch_address__c,Currency__c,AB_CODE__c,IBAN__c,Shipper__c,Country__c,Swiftcode__c,Item__r.id from cc_ST_OrderConfigData__c ];
CustomObject2__c custom2 = [Select id,Order__r.id,Product__r.id, Product__r.SKU__c,Product_Name__c,Quantity__c,Total_Price_c, Price__c,ItemTotal__c FROM ccrz__E_OrderItem__c];


Here field Item__r.id and Product__r.id contains same id.

I want to create a table and display in following format in vf page
Table
Best Answer chosen by Priyesh Misquith 12
David Zhu 🔥David Zhu 🔥
You may refer to the code snippet below.
 
public class yourcontroller 
{
    public class dataWrapper
    {
        public string attn {get;set;}
        public string Product{get;set;}
        .....
        //other fields in the table
    }

    public List<dataWrapper> dataContent {get;set;}  //this one will be used on VF page for displaying content in datatable


    public void PopulateData()
    {
        dataContent = new List<dataWrapper>();

        List<cc_ST_OrderConfigData__c > custom1List =[select id,Attn__c,Forwarder__c,Branch_address__c,Currency__c,AB_CODE__c,IBAN__c,Shipper__c,Country__c,Swiftcode__c,Item__r.id from cc_ST_OrderConfigData__c ];
        List<ccrz__E_OrderItem__c];> custom2List = [Select id,Order__r.id,Product__r.id, Product__r.SKU__c,Product_Name__c,Quantity__c,Total_Price_c, Price__c,ItemTotal__c FROM ccrz__E_OrderItem__c];

        Map<String,cc_ST_OrderConfigData__c> custom1Map = new Map<String,cc_ST_OrderConfigData__c>();
        for (cc_ST_OrderConfigData__c c : custom1List)
        {
            if (!custom1Map.contansKey(c.Item__r.id))
            {
                custom1Map.put(c.Item__r.Id,c);
            }
        }

        for (cc_ST_OrderConfigData__c c : custom1List)
        {
            if (custom1Map.containsKey(c.Product__r.id))
            {
                dataWrapper data = new dataWrapper();
                cc_ST_OrderConfigData__c cust1 = custom1Map.get(c.Product__r.Id);
                data.attn = cust1.attn__c;
                data.product = c.product__r.id;
                .......
                //populate other fields
                
                dataContent.add(data);
            }
        }

    }
  
}

 

All Answers

David Zhu 🔥David Zhu 🔥
You may refer to the code snippet below.
 
public class yourcontroller 
{
    public class dataWrapper
    {
        public string attn {get;set;}
        public string Product{get;set;}
        .....
        //other fields in the table
    }

    public List<dataWrapper> dataContent {get;set;}  //this one will be used on VF page for displaying content in datatable


    public void PopulateData()
    {
        dataContent = new List<dataWrapper>();

        List<cc_ST_OrderConfigData__c > custom1List =[select id,Attn__c,Forwarder__c,Branch_address__c,Currency__c,AB_CODE__c,IBAN__c,Shipper__c,Country__c,Swiftcode__c,Item__r.id from cc_ST_OrderConfigData__c ];
        List<ccrz__E_OrderItem__c];> custom2List = [Select id,Order__r.id,Product__r.id, Product__r.SKU__c,Product_Name__c,Quantity__c,Total_Price_c, Price__c,ItemTotal__c FROM ccrz__E_OrderItem__c];

        Map<String,cc_ST_OrderConfigData__c> custom1Map = new Map<String,cc_ST_OrderConfigData__c>();
        for (cc_ST_OrderConfigData__c c : custom1List)
        {
            if (!custom1Map.contansKey(c.Item__r.id))
            {
                custom1Map.put(c.Item__r.Id,c);
            }
        }

        for (cc_ST_OrderConfigData__c c : custom1List)
        {
            if (custom1Map.containsKey(c.Product__r.id))
            {
                dataWrapper data = new dataWrapper();
                cc_ST_OrderConfigData__c cust1 = custom1Map.get(c.Product__r.Id);
                data.attn = cust1.attn__c;
                data.product = c.product__r.id;
                .......
                //populate other fields
                
                dataContent.add(data);
            }
        }

    }
  
}

 
This was selected as the best answer
Priyesh Misquith 12Priyesh Misquith 12
Hi David Zhu.

I am getting error on the line 32 because Product__r.id is the field in ccrz__E_OrderItem__c and not on cc_ST_OrderConfigData__c .
Priyesh Misquith 12Priyesh Misquith 12

Thanks for the help  

I fixed the code David Zhu.

for (ccrz__E_OrderItem__c c : custom1List)
        {
            if (custom1Map.containsKey(c.Product__r.id))
            {
                dataWrapper data = new dataWrapper();
                cc_ST_OrderConfigData__c cust1 = custom1Map.get(c.Product__r.Id);
                data.attn = cust1.attn__c;
                data.product = c.product__r.id;
                .......
                //populate other fields
                
                dataContent.add(data);
            }
        }