You need to sign in to do that
Don't have an account?
Sabrent
<apex:commandButton>
Can a command button call two actions at the same time?
I am in a situation where I have two methods Save and Update. I want to either invoke the two methods in one command button action or instantiate method1 in method2 so that the command button will first call method1 and then method2.
Thanks
Oh it seems you want to return to some page after all operations. Modify your code as:
public Pagereference uploadDocument(){
if (this.attachment != null) this.attachment = null;
this.isExempt = 'document';
this.attachment = newAttachment();
this.exemptionComments = '';
if (reqId != null){
Requirement__c reqDoc = [Select Id, Name, Template_Requirement__r.NameFromRequirement__cWhere Id = :this.reqId limit1];
if(reqDoc != null){
this.CurrentDocRequirement = reqDoc.Name;
this.CurrentDocReqTitle = reqDoc.Template_Requirement__r.Name;
}
}
this.RequirementID = this.reqId;
//Now save your record and return to the desired page you want
saveUpload();
PageReference newPage = new PageReference(newPageUrl);
newPage.setRedirect(true);
return newPage;
}
public void saveUpload() {
// logic here
}
Let me know if this works.
Regards,
Lakshman
All Answers
Yes you can.
<apex:commandButton value="Click Me" action = "{!method2}" onClick = "name1"/>
<apex:actionFunction name = "name1" action = "{!method1}"/>
cool thanks! I'll let you know how i go.
A little correction in above post:
<apex:commandButton value="Click Me" action = "{!method2}" onClick = "name1();"/>
Call actionFunction in this way, and will work fine.
Rather you can also do like this:
<apex:commandButton value="Click Me" action = "{!method1}"/>
and then in the controller
public void method1()
{
//do desired operations and at the end call method2() as below
method2();
}
Regards,
Lakshman
Thanks to vaghish and Lakshman;
I had earlier tried doing what Lakshman suggested. However got the error 'Non-void method might not return a value or might have statement after a return statement
// This is my code
publicPagereference uploadDocument(){
if (this.attachment != null) this.attachment = null;
this.isExempt = 'document';
this.attachment = newAttachment();
this.exemptionComments = '';
if (reqId != null){
Requirement__c reqDoc = [Select Id, Name, Template_Requirement__r.NameFromRequirement__cWhere Id = :this.reqId limit1];
if(reqDoc != null){
this.CurrentDocRequirement = reqDoc.Name;
this.CurrentDocReqTitle = reqDoc.Template_Requirement__r.Name;
}
}
this.RequirementID = this.reqId;
returnnull;
saveUpload();
}
public PageReference saveUpload() {
// logic here
}
Oh it seems you want to return to some page after all operations. Modify your code as:
public Pagereference uploadDocument(){
if (this.attachment != null) this.attachment = null;
this.isExempt = 'document';
this.attachment = newAttachment();
this.exemptionComments = '';
if (reqId != null){
Requirement__c reqDoc = [Select Id, Name, Template_Requirement__r.NameFromRequirement__cWhere Id = :this.reqId limit1];
if(reqDoc != null){
this.CurrentDocRequirement = reqDoc.Name;
this.CurrentDocReqTitle = reqDoc.Template_Requirement__r.Name;
}
}
this.RequirementID = this.reqId;
//Now save your record and return to the desired page you want
saveUpload();
PageReference newPage = new PageReference(newPageUrl);
newPage.setRedirect(true);
return newPage;
}
public void saveUpload() {
// logic here
}
Let me know if this works.
Regards,
Lakshman
This worked!!! Cool!!! Thanks a lot. I really appreciate your help.