I am creating a new custom button or link, and when i try to use a Visualforce page my content dropdown list is empty. How do i get a VF page to trigger on a custom button or link.
[SalesForce] Custom Button and Link can’t use VF Page
Related Solutions
You can call your method on button click as shown below
<apex:page standardController="Opportunity" showHeader="false" sidebar="false">
<script>
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
//This is your javascript
function SaveNote()
{
var note = document.getElementById('frmid:pgblk:pgblksection:descriptionfield').value;
if (note != null) {
var project = new sforce.SObject("Opportunity");
project.id = "{!Opportunity.Id}";
var date = "{!TODAY()}";
// var user = "{!$User.Alias}";
var user = "{!$User.CommunityNickname}";
var oldnote = "{!JSENCODE(Opportunity.Description)}";
var prepend = date+" "+user+" - "+note+"\n";
var newnote = prepend+oldnote;
project.Description = newnote;
var result = sforce.connection.update([project]);
window.location.reload();
return false;
}
}
</script>
<apex:form id="frmid">
<apex:pageBlock id="pgblk">
<apex:pageBlockSection columns="3" id="pgblksection">
<apex:inputfield id="descriptionfield" value = "{! Opportunity.Description}" />
<apex:commandButton onclick="return SaveNote();" value="Add Note" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
You need to use recordSetVar
on your page to make it available for custom List view button.
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" extensions="tenPageSizeExt">
<apex:form >
<apex:pageBlock title="Edit Stage and Close Date" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="opp">
<apex:column value="{!opp.name}"/>
<apex:column headerValue="Stage">
<apex:inputField value="{!opp.stageName}"/>
</apex:column>
<apex:column headerValue="Close Date">
<apex:inputField value="{!opp.closeDate}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Best Answer
You need to ensure your Visualforce page uses a Standard Controller for your object.
For Detail Page custom buttons...
For List View custom buttons...
Then Salesforce will display your pages in the drop down list.
You can read a more detailed walk through and some security considerations here.