You need to sign in to do that
Don't have an account?
Wendy Sadeh
Updating Opportunity StageName with custom extension
On the opportunity I have a custom button that does some verification and if the verification passes, I want to update the stage name. My update code has no affect. Below is posted my code snippets.
Here is the apext code:
Here is the apext code:
<apex:page standardController="Opportunity" extensions="CustomOpportunitySaveExtension"> <apex:form > <apex:pageBlock title="Opportunity Submission"> <apex:pageBlockSection title="Please fill the below fields before submitting the Opportunity form" columns="1"> <apex:outputText style="color:red" value="{!CheckAndValidate}" escape="false"/> <apex:commandButton value="Go Back to Opportunity Form" action="{!getBack}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public class CustomOpportunitySaveExtension { private final Opportunity opp; private final ApexPages.StandardController oController; public Id OpportunityId {get; set;} public CustomOpportunitySaveExtension (ApexPages.StandardController stdController) { this.opp = (Opportunity)stdController.getRecord(); this.oController = stdController; } public PageReference getBack() { String refUrl; refUrl = '/'+ opp.Id ; PageReference ref = new PageReference(refUrl); ref.setRedirect(true); return ref; } public String getCheckAndValidate() { List<Opportunity> opportunitylst = [ SELECT Id, Name, PACEPartner_Project_Number__c, Transaction_Manager__c, StageName, FROM Opportunity WHERE Id = :opp.Id LIMIT 1 ]; Opportunity opportunity; String validationMessage = ''; Boolean isMissed = false; if ( opportunitylst.size() > 0 ) { opportunity = opportunitylst[0]; system.debug('Oppurtunity Name : ' + opportunity.Name); // Project Status - Section Starts if(opportunity.Name == null) { validationMessage += 'Project Name - Opportunity Name'; isMissed = true; } if(!isMissed) { // This is where I want to update the stage name. It has no affect. opportunity.StageName = 'Qualified Lead'; oController.save(); validationMessage += 'Your application is submitted successfully'; } }
Line number 4:
public String validationMessage {get; set;}
All Answers
Please replace the below code and verify the same.
Regards,
Mahesh
Thanks for the quick reply.
When I change it to update opp; and run the code in my sandbox I get "Error: Error occurred while loading a Visualforce page. ".
I am not sure where to look for a "live" debug log. When I run tests I can see my debug log, but not when I am viewing pages in my sandbox instance.
-w
And preview the VF page by passing the Opportunity Id;
Something like below:
https://cs40.salesforce.com/apex/VFPageName?Id=006a000000v3iw6
If you can send me the proper error message, it will be easy to fix it.
Thank you for solving the mystery of debug logs!
Here is the message:
DML currently not allowed
CustomOpportunitySaveExtension.getCheckAndValidate: line 935, column
You class contains only 30 lines of code and why it is showing line number 935?
Regards,
Mahesh
<apex:outputText style="color:red" value="{!validationMessage}" escape="false" id="msg"/>
<apex:commandButton value="Save" action="{!getCheckAndValidate}" reRender="msg"/>
In the controller
public PageReferencegetCheckAndValidate() {
....
.....
return new PageReference('/'+opp.Id);
}
Error:(1, 1) Unknown property 'OpportunityStandardController.validationMessage'
and controller now:
Line number 4:
public String validationMessage {get; set;}
I was getting the error: DML currently not allowed
You cannot do any data manipulate in a getXXX method.
I altered the code to be:
and