Skip to main content
Hey,

Here is the requirement.

Basically I have to add a button to the Contact related list in the Account Layout. When that button is clicked it sould redirect to a Visualforce Page with all the related Contacts and the contact details for that Account and the details should be editable with a save button.

Its basically Mass Update for Related List Details.

I was able to get all related contacts and give inline edit support for them and wrote a save function for the same. I don't know what is wrong but you can edit but when you click save it wont save to salesforce DB.

Here is the controller,

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;

}

}

Here is the Visualforce page,

 

<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!

3 件の回答
  1. 2017年10月10日 7:31
    @Akshay_Dhiman

    Thanks 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!
0/9000