Here is the controller,
Here is the Visualforce page,public class stanset_EX_Controller1{
private final Contact setCon;
public stanset_EX_Controller1(ApexPages.StandardSetController controller)
{
this.setCon = (Contact) controller.getRecord();
}
List<Contact> Conts;
public List<Contact> getConts(){
return Conts;
}
public ApexPages.StandardSetController doSomething{
get {
// do something with the selected records
doSomething = new ApexPages.StandardSetController(
Database.getQueryLocator([
SELECT Phone,
Name,
AccountId,
Email,
FirstName,
Id,
LastName,
Title
FROM Contact
WHERE AccountId
= :ApexPages.currentPage().getParameters().get('id')
]));
return doSomething;
}
private set;
}
public List<Contact> getAccountContactsPagination() {
//system.debug(doSomething.getRecords()+'ppp');
return (List<Contact>) doSomething.getRecords();
}
public PageReference save() {
system.debug(getAccountContactsPagination());
//update(getAccountContactsPagination());
PageReference pageRef = ApexPages.currentPage();
pageRef.setRedirect(true);
return pageRef;
}
}
<apex:page
standardController="Contact"
recordSetVar="contacts"
extensions="stanset_EX_Controller1" showHeader="true" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!accountContactsPagination}" var="contact">
<apex:column value="{!contact.name}"/>
<apex:column value="{!contact.FirstName}"/>
<apex:column value="{!contact.LastName}"/>
<apex:column value="{!contact.Title}"/>
<apex:column value="{!contact.Id}"/>
<apex:column>
<apex:outputField value=" {!contact.Email}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:column value="{!contact.Phone}"/>
<apex:inlineEditSupport />
</apex:pageBlockTable>
<apex:pageBlockButtons location="bottom">
<!-- <apex:commandButton value="Do Something" action="{!doSomething}"/> -->
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Tried many things dont know what is wrong with the code.
HELP!! Thanks In Advance! Cheers!@Akshay_DhimanThanks for the quick reply mate. I knew how to do with a custom controller. But the thing was I had to give Pagination as well and it should take inputs from the user so that they can set how many records they want to see. Because of this I had to use StandardSetController which gives very easy pagination.Thanks for the reply tough, I was able to get it done 1hr later i posted the question. My code was pretty much ok. The problem was that i used apex:pageBlockButtons tag for button and for some reason it was not working and my save function was was a bit off. All I had to use was .Save();.Thanks you very much here is the code, same as above and some parts alterd. VF Page: <apex:page standardController="Contact"
recordSetVar="contacts"
extensions="stanset_EX_Controller1" showHeader="true" sidebar="false" >
<apex:form >
<div draggable="false" class=" slds-align--absolute-center ">
<apex:commandButton value="Save" action="{!save}" styleClass="slds-button--icon-more"/>
<apex:commandButton value="Cancel" action="{!cancel}" styleClass="slds-button--icon-more"/>
</div>
<apex:pageBlock >
<apex:pageBlockTable value="{!accountContactsPagination}" var="contact">
<apex:column >
<apex:outputField value=" {!contact.FirstName}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:column >
<apex:outputField value=" {!contact.LastName}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:column >
<apex:outputField value=" {!contact.Phone}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:column >
<apex:outputField value=" {!contact.Email}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:column >
<apex:outputField value=" {!contact.Title}">
<apex:inlineEditSupport disabled="false"/>
</apex:outputField>
</apex:column>
<apex:inlineEditSupport />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
StandardSetController:
public class stanset_EX_Controller1{
private final Contact setCon;
public stanset_EX_Controller1(ApexPages.StandardSetController controller)
{
this.setCon = (Contact) controller.getRecord();
}
public ApexPages.StandardSetController doSomething{
get {
if (doSomething == null) {
// do something with the selected records
doSomething = new ApexPages.StandardSetController(
Database.getQueryLocator([
SELECT Phone,
Birthdate,
Name,
AccountId,
Email,
FirstName,
Id,
LastName,
Title
FROM Contact
WHERE AccountId
= :ApexPages.currentPage().getParameters().get('id')
]));
}
return doSomething;
}
private set;
}
public List<Contact> getAccountContactsPagination() {
System.debug(doSomething.getRecords());
return (List<Contact>) doSomething.getRecords();
}
public PageReference save() {
system.debug(getAccountContactsPagination());
// upsert (getAccountContactsPagination());
doSomething.save();
PageReference pageRef = ApexPages.currentPage();
pageRef.setRedirect(true);
return pageRef;
}
}
Need to do pagination for the same.
Thnaks hope it helps you.Cheers!