+ Start a Discussion
BridgetreeBridgetree 

pageBlockTable object contents to fields of another object

I have pageblock table having contents of one object. i have cretaed another custom object

with similar fields of table. I want to create instance of the pageBlocktable with the table of

the custom object fields.

 

How can i do it..

 

 

Any suggestion with code????

 

nadi

Ankit AroraAnkit Arora

Can you please explain more what do you mean by "Instance of the PageBlockTable" ?

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

BridgetreeBridgetree

I don mean anything strange. I jus want to know how to have pageBlockTable with fields

belongs to two different objects.. rest i will do it..

 

 

Ankit AroraAnkit Arora

If you want to show two different object data in pageblock table then I think you need a wrapper class to do this. Lets say i have a list of account and list of contact (considering we are not fetching the related contacts), now I can use only one list in pageblocktable. I can not loop on both together in "value" attribute of pageblocktable.

 

To do this you need a wrapper class in which both list will be passed and a single instance of wrapper will be returned. Now you can use that instance in pageblocktabe and display values of both objects.

 

Here is the sample code :

 

VFP

 

<apex:page controller="tt">
    <apex:pageBlock>
        <apex:pageBlockSection>
            <apex:pageBlockTable value="{!wrapper}" var="wrap">
                <apex:column headerValue="Account Name" value="{!wrap.accRec.Name}"/>
                <apex:column headerValue="Contact Name" value="{!wrap.conRec.Name}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 

Class

 

public class tt
{
    public List<Account> accLst {get; set;}
    public List<Contact> conLst {get; set;}
    public List<MyWrapper> wrapper {get; set;}

    public tt()
    {
        accLst = [select id,name from account limit 5] ;
        conLst = [select id,name from contact limit 5] ;
        wrapper = new List<MyWrapper>() ;
        for(Integer i=0 ; i < 5 ; i++)
            wrapper.add(new MyWrapper(accLst[i] , conLst[i])) ;
    }
    
    public class MyWrapper
    {
        public Account accRec {get; set;}
        public Contact conRec {get; set;}
        
        public MyWrapper(Account acc , Contact con)
        {
            accRec = acc ;
            conRec = con ;
        }
    }
}

 

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

BridgetreeBridgetree

Thanks Ankit Sir, This Code is awsome but solves my requirement 50%

 

If we take the same example i want to copy the fields in Account fields to Contact fields.

 

Please tell me the modification

Ankit AroraAnkit Arora

Sorry I didn't get you. Can you please explain more?

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

BridgetreeBridgetree

I have a Prdouct STD object and Trade Custom object. I have written a VFP for Trade object. Now with the above code i will get the products into the pageBlockTable,  i will click the save button. 

Once all other stuffs are done, i will click the save button. this creates a record in trade object.   i want the same pageBlockTable to be in the record. So what is required is that, The values in the fields of Product object  that come in the pageBlockTable should be copied to fields of Trade Object. i have created similar fields in the Trade object as well.

 

 

hkp716hkp716

Did you find a solution?  I have a similar requirement as well.

 

-Hkp716