You need to sign in to do that
Don't have an account?
Glen.ax1034
Custom Button returns values to custom method of extension class
I am getting an error when saving, am I declaring the method wrong? Can I use an extension class?
Error: action="{!savepackage}": Unknown method 'Packages__cStandardController.savepackage()'
relevant code:
global class packageextensions { private final Packages__c PackageObj; public packageextensions (ApexPages.StandardController controller) { this.PackageObj= (Packages__c)controller.getSubject(); } global static Boolean getAddDisposition(List<Product2> pproducts) { return false; }
The code that is erroring:
<apex:page standardController="Packages__c" extensions="packageextensions"> <apex:form > <apex:commandButton action="{!savepackage}" value="Save Package"/> </apex:form>
try this :
Visualforce Page :
**************************
<apex:page standardController="Package__c" extensions="packageextension" >
<apex:form >
<apex:commandButton action="{!savepackage}" value="Save Package"/>
</apex:form>
</apex:page>
Controller :
****************************
public class packageextension {
public packageextension (ApexPages.StandardController controller) {
}
public pagereference savepackage()
{
return null;
}
}
I have tried it in my Developer Org and it is working.
Please mark it as the solution if it answers your question and if you have any question, let me know.
Ckeck My Blog
All Answers
Hi ,
As I can see, you have not declared savepackage() method in the extension class. You need to give defination of savepackage() in extension class. Then after you will be able to use it in visualforce page.
Add below mention line in extension class and error would be gone :
public pagereference savepackage(){}
Please mark it as the solution if it answers your question and if you have any question, let me know.
Ckeck My Blog
yeah, i changed the "getaddisposition" to "savepackage" --- still failing. i think that this is simply because i dont know how to declare the class:
i'm getting an error: unexpected token: 'savepackage'
how do i declare it, presumably above, so that it doesnt error?
try this :
Visualforce Page :
**************************
<apex:page standardController="Package__c" extensions="packageextension" >
<apex:form >
<apex:commandButton action="{!savepackage}" value="Save Package"/>
</apex:form>
</apex:page>
Controller :
****************************
public class packageextension {
public packageextension (ApexPages.StandardController controller) {
}
public pagereference savepackage()
{
return null;
}
}
I have tried it in my Developer Org and it is working.
Please mark it as the solution if it answers your question and if you have any question, let me know.
Ckeck My Blog
Last question. Do you know how to get back the value of an array of checkboxes? I want to create an array of checkboxes, one check box for each Packages__c sObject type that my page displays. From there, I want to run apex code to link that particular Product2 to the Package via a many:many relationship and do a few other parent.id references.
Do you know the correct syntax to pass just a list of Product2.id's from apex checkboxes into a class/method/function of apex?
figured it out:
Great !!