Activity Forums Salesforce® Discussions How can i  display records of account, contacts, opty on the same Salesforce Visualforce page and then process the selected records using wrapper class?

  • Shaharyar

    Member
    June 16, 2017 at 7:19 am

    /*VISUAL FORCE PAGE AND CONTROLLER WITH WRAPPER CLASS*/

    <apex:page controller="MultipleContact" sidebar="false">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockTable value="{!listContact}" var="cnct" id="ref">
    <apex:column headervalue="Last Name">
    <apex:inputfield value="{!cnct.con.LastName}"/>
    </apex:column>
    <apex:column headervalue="First Number">
    <apex:inputfield value="{!cnct.con.FirstName}"/>
    </apex:column>
    <apex:column headervalue="Email">
    <apex:inputfield value="{!cnct.con.Email}"/>
    </apex:column>
    <apex:column headervalue="Title">
    <apex:inputfield value="{!cnct.con.title}"/>
    </apex:column>
    <apex:column headervalue="RemoveContact">
    <apex:inputCheckbox value="{!cnct.isSelected}"/>
    </apex:column>
    </apex:pageBlockTable>
    <apex:pageblockbuttons >
    <apex:commandButton value="Add More Contact" action="{!addContact}" reRender="ref" />
    <apex:commandButton value="Save Contact" action="{!SaveContact}"/>
    <apex:commandButton value="Remove Contact" action="{!RemoveContact}"/>
    </apex:pageblockbuttons>
    </apex:pageBlock>
    </apex:form>
    </apex:page>
    public class MultipleContact{

    public list<cContact> listContact{get;set;}
    public MultipleContact(){ //constructor
    listContact=new list<cContact>();
    listContact.add(new cContact(new contact()));
    }
    public void addContact() {
    Contact cnct = new Contact();
    MultipleContact.cContact cn = new MultipleContact.cContact(cnct);
    listContact.add(cn);
    }
    public pagereference saveContact(){
    List<Contact> myList = new List<Contact>();
    for(cContact c : listContact){
    myList.add(c.con);
    }
    pagereference pg=new pagereference('/003/o');
    insert myList;
    return pg;
    }
    public pageReference RemoveContact() {
    List<cContact> li = listContact;
    for(Integer i=0 ; i<li.size(); i++){
    if(li[i].isSelected == true){
    listContact.remove(i);
    }
    }
    pageReference pg1=new pageReference('/');
    //delete listContact;
    return null;
    }
    //Inner class of contact
    public class cContact{
    public Contact con{get;set;}
    public boolean isSelected{get;set;}
    public cContact(Contact con){
    this.con = con;
    isSelected = false;
    }
    }

    }

  • Vishant

    Member
    June 16, 2017 at 8:58 am

    Actually i have to deal with all three of them(Account,contact,opportunity) on the same VF page and after selection particular records i want them to get displayed on a new page block

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos