How to call a visualforce page from a custom button?

  • I have the following VisualForce page:

    <apex:page standardController="Inquery__c" 
        "First Name","Last Name","Email","Qualification"
        <apex:repeat value="{!accvar}" var="a">
            <apex:outputText rendered="{!NOT(a.Download__c)}">
                {!a.First_Name__c}, {!a.Last_Name__c}, {!a.Email__c}, {!a.Quilification__c}

    That downloads all the records in a CSV file, That have the check box field Download__c unchecked.

    How can I call this VF from a custom button on the Inquery__c custom object?

    When I choose the Content Source as Visualforce Page, No content is available!

    What am I doing wrong?


  • Sergej Utko

    Sergej Utko Correct answer

    8 years ago

    Use a javascript for that:

    window.location = 'apex/YourVisualforcePage';

    This is my example of the button:

    enter image description here

    And the visualforce page:

    <apex:page standardController="Account" recordSetVar="accounts">
            <apex:pageBlockTable value="{!accounts}" var="a">
                <apex:column value="{!}"/>
                <apex:column value="{!a.CustomerPriority__c}"/>

    Here is the result page:

    enter image description here

    And here is an screenshot of the account page and the result of the click on the button:

    enter image description here

    Now add the button to the object page layout. Go to some of the object records page, find a lind called Edit Layout and click on it:

    enter image description here

    Now drag your button to the page and drop it in to the Custom buttons area, then save the layout:

    enter image description here

    What's the best practice for doing this from LEX, now that the window object is taken away and OnClick JS buttons are disabled?

    Yea this answer is only applicable to Salesforce Classic not LEX

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM

Tags used