1

I want to add a custom button to the list view of Contacts but it is not working. I go to Object Manager... Contacts... Search Layouts... List View... Edit... Custom Buttons... add my button to the list of Selected Buttons. When I go back to Contacts, it does not appear. If I remove Standard Buttons by unchecking them, nothing changes. Any direction would be appreciated.

I'm using Lightning. enter image description here

enter image description here enter image description here

public class createNewContactController_ext {
//variables for the student
private final Contact con;
private ApexPages.StandardController stdController;
String StudentRecordType = '0121H000001If0DQAS';


//variables for dependent spouse
public List<Contact> spsList {get;set;} //using list so that I don't have to declare each variable
public Integer rowNumsps{get;set;}
String DepedendentRecordType = '0121H000001If0IQAS';


//variables for dependent children
public List<Contact> depList {get;set;}
public Integer rowNum{get;set;}

//initialize 
public createNewContactController_ext(ApexPages.StandardController stdController) {
    this.con = (Contact)stdController.getRecord();
    depList = new List<Contact>();  
    spsList = new List<Contact>();
}
    //for inserting additional rows in dependent spouse table
public void insertRowsps(){
    spsList.add(new Contact(recordTypeID=DepedendentRecordType)); 
}

    //for deleting rows from dependent spouse table
public void delRowsps(){
    rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('indexsps'));
    depList.remove(rowNumsps);   
}

//for inserting additional rows in dependent children table
public void insertRow(){
    depList.add(new Contact(recordTypeID=DepedendentRecordType)); 
}


//for deleting rows from dependent children table
public void delRow(){
    rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
    depList.remove(rowNum);   
}

//save the records
public PageReference save(){

    //save the student
    insert con;

    //save the spouse
    insert spsList;
    for (Contact sps : spsList){
        hed__Relationship__c spsrel = new   hed__Relationship__c(hed__Contact__c=con.Id, hed__RelatedContact__c=sps.Id, hed__Type__c='Spouse');
      insert spsrel;
    }

    //save the child dependents
    insert depList;
    for (Contact dep : depList){
      hed__Relationship__c rel = new    hed__Relationship__c(hed__Contact__c=con.Id, hed__RelatedContact__c=dep.Id, hed__Type__c='Child');
      insert rel;
    }    

    //redirect to the detail page of the student
    PageReference redirectPage = new ApexPages.StandardController(con).view();
    redirectPage.setRedirect(true);
    redirectPage.getParameters().put('id',con.Id);
    return redirectPage;
    }

}

the vf page:

    <apex:page standardController="Contact" extensions="createNewContactController_ext" docType="html-5.0" >
<apex:pageBlock title="Student">
    <apex:form >
        <apex:pageBlockSection >       
            <apex:inputField value="{!Contact.FirstName}" />
            <apex:inputField value="{!Contact.LastName}" />
            <apex:inputField value="{!Contact.Email}" required="true" />
            <apex:inputField value="{!Contact.Birthdate}" showDatePicker="true"/>
            <apex:inputField value="{!Contact.Affiliated_Community__c}" />
            <apex:inputField value="{!Contact.Beneficiary_Number__c}" />
            <apex:inputField value="{!Contact.Birth_Place__c}" />
            <apex:inputField value="{!Contact.Social_Insurance_Number__c}" />
            <apex:inputField value="{!Contact.hed__Gender__c}" />
            <apex:inputField value="{!Contact.Counselor__c}" />
            <apex:inputField value="{!Contact.Permanent_Code__c}" />
            <apex:inputField value="{!Contact.Facebook_Profile__c}" />
            <apex:inputField value="{!Contact.Language_Preference__c}" />
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Student Permanent Address">
            <apex:inputField value="{!Contact.MailingStreet}" />
            <apex:inputField value="{!Contact.MailingCity}" />
            <apex:inputField value="{!Contact.MailingState}" /> 
            <apex:inputField value="{!Contact.MailingPostalCode}" label="Province" />
            <apex:inputField value="{!Contact.MailingCity}" />
            <apex:inputField value="{!Contact.MailingState}" />        
        </apex:pageBlockSection> 
        <apex:pageBlock title="Dependent Spouse" >
            <apex:variable var="rowNumsps" value="{!0}"  />  
            <apex:pageBlockTable value="{!spsList}" var="spstable">
                <apex:facet name="footer">
                    <apex:commandLink value="Add" action="{!insertRowsps}"/>
                </apex:facet>
                <apex:column headerValue="First Name">
                    <apex:inputField value="{!spstable.FirstName}"/>
                </apex:column>
                <apex:column headerValue="Last Name">
                    <apex:inputText value="{!spstable.LastName}"/>
                </apex:column>   
                <apex:column headerValue="Birthdate">
                    <apex:inputField value="{!spstable.Birthdate}"/>
                </apex:column>   
                <apex:column headerValue="Beneficiary Number">
                    <apex:inputField value="{!spstable.Beneficiary_Number__c}"/>
                </apex:column>   
                <apex:column headerValue="Social Insurance Number">
                    <apex:inputField value="{!spstable.Social_Insurance_Number__c}"/>
                </apex:column>
                <apex:column headerValue="Delete" >
                    <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                        <apex:param value="{!rowNumsps}" name="indexsps" />
                    </apex:commandLink>
                    <apex:variable var="rowNumsps" value="{!rowNumsps+1}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:variable var="rowNum" value="{!0}"  />
        <apex:pageBlock title="Dependent Children" >
            <apex:variable var="rowNum" value="{!0}"  />  
            <apex:pageBlockTable value="{!depList}" var="deptable">
                <apex:facet name="footer">
                    <apex:commandLink value="Add" action="{!insertRow}"/>
                </apex:facet>
                <apex:column headerValue="First Name">
                    <apex:inputField value="{!deptable.FirstName}"/>
                </apex:column>
                <apex:column headerValue="Last Name">
                    <apex:inputText value="{!deptable.LastName}"/>
                </apex:column>   
                <apex:column headerValue="Birthdate">
                    <apex:inputField value="{!deptable.Birthdate}"/>
                </apex:column>   
                <apex:column headerValue="Beneficiary Number">
                    <apex:inputField value="{!deptable.Beneficiary_Number__c}"/>
                </apex:column>   
                <apex:column headerValue="Social Insurance Number">
                    <apex:inputField value="{!deptable.Social_Insurance_Number__c}"/>
                </apex:column>         
                <apex:column headerValue="Delete" >
                    <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                        <apex:param value="{!rowNum}" name="index" />
                    </apex:commandLink>
                    <apex:variable var="rowNum" value="{!rowNum+1}"/>
                </apex:column>          
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:commandButton value="save" action="{!save}" />  
    </apex:form>    
</apex:pageBlock>
</apex:page>
  • It sounds like this might be a JavaScript button. Is that correct? – sfdcfox Jan 9 at 15:35
  • it's a list button pointing to a VF page. I added a screenshot of the button. – Michael C Jan 9 at 16:28
  • 1
    What Visualforce Page are you using? What do you specify for its standardController? Can you share the markup for that page? Specifically what we need to see is just your <apex:page> tag. – Adrian Larson Jan 9 at 16:29
  • And is the Visualforce page marked as available for the Lightning Experience? – David Reed Jan 9 at 16:32
  • Can you change the list view filter? The custom VF page list view button is not visible in "Recently Viewed " list view for some reason – Pranay Jaiswal Jan 9 at 16:45
2

You have to use recordSetVar to add a button to List view. Adding recordSetVar makes it a StandardSetController and thus makes it available in that picklist to select.

<apex:page standardController="Contact" extensions="createNewContactController_ext" docType="html-5.0" recordSetVar="contacts">

Also, The list view VF page button won't be visible in "Recently Viewed" List view, you have to select any other listview to see that button.

EDIT:

Your apex Extension should be StandardSetController extension as well. StandardSetControllerExtension works on Set of records.

public class createNewContactController_ext {

    public createNewContactController_ext(ApexPages.StandardSetController controller){
    // constructor logic
    }
}

NOTE: StandardSetController allows you to use the page in a List Button, whereas using a StandardController allows you to use it in a Detail Button.

Once you save your VF Page and Apex Class, It will be visible for you to add to Listview.

Src : https://salesforce.stackexchange.com/a/144831

  • this gives me the error: Unknown constructor 'createNewContactController_ext.createNewContactController_ext(ApexPages.StandardSetController controller)' – Michael C Jan 9 at 18:40
  • even if I create a new button Display Type = List Button and Content Source = URL, the button does not display in the Contacts list page – Michael C Jan 9 at 18:42
  • @MichaelC can you post your apex code? Your Apex code in Extension should have StandardSetController as the constructor – Pranay Jaiswal Jan 9 at 19:01
  • @MichaelC added logic with explanation – Pranay Jaiswal Jan 9 at 19:17
  • Thanks, that makes sense. However, the page will not be handling record sets but only a single record. The purpose of the page is the create records in multiple objects at the same time. So I'd like a button next to the New button that links to this VF page. I'm guessing that my inability to add a button next to the New (or somewhere in that section) has something to do with Search Layouts. Even if I add a generic, URL link button, it doesn't show up there. – Michael C Jan 9 at 19:31
3

In order to use your page as list button, you need to use standard list controller instead of standard controller like this:

   <apex:page standardController="Contact" recordSetVar="conList" extensions="createNewContactController_ext">

Refer to below link for more details: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm

  • I have followed all the steps in the link you sent, thanks. However, for Step 5, I want to add a custom button to Search Layouts... List View. This is the part that is not working for me. – Michael C Jan 9 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.