You need to sign in to do that
Don't have an account?
Frank Jordan
Update a field with a visualforce button
I need a custom button that when pressed, changes the owner of the record and saves the record. I have the class already written, I just need the apex page to go along with it.
Here is the class that I have:
public with sharing class classSubmitToLegal {
public Agreement_Request__c a{get;set;}
public classSubmitToLegal() {
a = new Agreement_Request__c ();
a = [select Business_Unit__c from Agreement_Request__c Where Id=: ApexPages.currentPage().getParameters().get('Id')];
}
public void someMethod() {
if(a.Business_Unit__c == 'EIS') {
a.Business_Unit__c = 'EIS Queue';
update a;
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You have changed the owner');
Apexpages.addMessage(errorMessage);
} else {
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You cannot update');
Apexpages.addMessage(errorMessage);
}
}
}
Here is the class that I have:
public with sharing class classSubmitToLegal {
public Agreement_Request__c a{get;set;}
public classSubmitToLegal() {
a = new Agreement_Request__c ();
a = [select Business_Unit__c from Agreement_Request__c Where Id=: ApexPages.currentPage().getParameters().get('Id')];
}
public void someMethod() {
if(a.Business_Unit__c == 'EIS') {
a.Business_Unit__c = 'EIS Queue';
update a;
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You have changed the owner');
Apexpages.addMessage(errorMessage);
} else {
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You cannot update');
Apexpages.addMessage(errorMessage);
}
}
}
You can try this code.
<apex:page extensions="classSubmitToLegal" standardController="Agreement_Request__c ">
<apex:form>
<apex:commandButton action="{!someMethod}" value="Submit To Legal" id="theButton"/>
</apex:form>
</apex:page>
All Answers
You'll want to research more into how action buttons function, and to avoid just doing your homework for you, i've intentionally not wired this basic visualforce page up to your button properly. Regardless, this should help you out:
You can try this code.
<apex:page extensions="classSubmitToLegal" standardController="Agreement_Request__c ">
<apex:form>
<apex:commandButton action="{!someMethod}" value="Submit To Legal" id="theButton"/>
</apex:form>
</apex:page>