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?
Tagged: Salesforce Development, Salesforce Visualforce, Salesforce Visualforce Page, Wrapper, Wrapper Class, Wrapper List
-
How can i display records of account, contacts, opty on the same Salesforce Visualforce page and then process the selected records using wrapper class?
Posted by Vishant on June 16, 2017 at 6:30 AMHow can i display records of account, contacts, opty on the same VF page and then process the selected records using wrapper class??
please explain it in detail (the exact working of wrapper class)
Vishant replied 8 years, 11 months ago 2 Members · 2 Replies -
2 Replies
-
/*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;
}
}}
- [adinserter block='9']
-
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.