You need to sign in to do that
Don't have an account?

Need List Button on Custom Object
I'm trying to create a List Button on a custom object (Test_Object__c) that is a related list to the Account object. I've created the VF page and Controller below, but I do not get the option of adding it to a custom list button. I am also trying to pre-populate a look-up field on Test_Object__c with the Account name. Can anyone tell me what I am doing wrong?
VF Page:
<apex:page standardController="Account" tabStyle="Account" extensions="TestController3">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:inputField value="{!L1.test1__c}"/>
<apex:inputField value="{!L1.test2__c}"/>
<apex:inputField value="{!L1.test3__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Save and New" action="{!News}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class TestController3{
public Account acct{get;set;}
public Level_1__c L1{get;set;}
public TestController3(ApexPages.StandardController controller) {
This.L1 = (Level_1__c)controller.getRecord();
}
public PageReference Save(){
L1.Company_Name__c = acct.Name;
insert L1;
PageReference ref = new PageReference('/'+acct.id);
return ref;
}
public PageReference News(){
return null;
}
public PageReference Cancel(){
return null;
}
}
Hi,
While creating the custom button, select javascript and then in the source definethe script to open the visualforce page
window.open('/apex/<VisualforcePageName>','_parent');
You can also write condition in which case the page shld be displayed and add the button to the search layout.
All Answers
Hi,
While creating the custom button, select javascript and then in the source definethe script to open the visualforce page
window.open('/apex/<VisualforcePageName>','_parent');
You can also write condition in which case the page shld be displayed and add the button to the search layout.
Hi,
I added that javascript to the button and it allowed me to add it to the List Button on the Account, but now I am getting the error below:
Visualforce Error
System.TypeException: Invalid conversion from runtime type SOBJECT:Account to SOBJECT:Level_1__c
Class.TestController3.<init>: line 8, column 1
Any idea why?