You need to sign in to do that
Don't have an account?
Custom Controller after getting Opportunity Id, how get other Opportunity fields for later use in a query
Hello All!
I have Custom Controller I want to call with a Custom Button on the Opportunity Page. The Custom Controller will get the Opportunity Id from the Opportunity page. I want to get an Opportunity Custom Field, OS_Number__c (Text 6) from the passed Opportunity Id then save OS_Number__c for use in another query.
My VF Page displays the data correctly when I hard-code the OS_Number__c as '44831' so that part seems to be working correctly.
How do I correct my Custom Controller to work without hard-coding?
How do I add the Custom Button to the Opportunity Page?
Thank you for your help!
Robert
Controller:
public class JoinedProposalCheckController { public List<Opportunity> OSNum {get;set;} public List<Opportunity> opptyList {get;set;} public JoinedProposalCheckController() { populateOSNum(); populateOpptyList(); } private void populateOSNum() { OSNum = [SELECT OS_Number__c FROM Opportunity WHERE Id = :ApexPages.currentPage().getParameters().get('id') LIMIT 1 ]; System.Debug('OSNum='+OSNum); } private void populateOpptyList() { opptyList = [SELECT Id, Name, Account.Name, OS_Number__c, Opportunity_Number__c, Joint_Proposal__c FROM Opportunity WHERE OS_Number__c = '44831' ]; } public List<Opportunity> getopptyList() { return opptyList; } }
VFP:
<apex:page Controller="JoinedProposalCheckController" showHeader="true" sidebar="false" tabStyle="Opportunity"> <apex:form id="JPForm"> <apex:pageBlock title="Opportunities List" > <apex:pageBlockSection > Please review Opportunities without a Joined Proposal </apex:pageBlockSection> <apex:pageBlockSection > <apex:pageBlockTable value="{!OpptyList}" var="op" width="100%"> <apex:column headerValue=" Opportunity"> <apex:outputLink value="/{!URLFOR(op.Id)}">{!op.Opportunity_Number__c} </apex:outputLink> </apex:column> <apex:column Value="{!op.Name}" headerValue="Opportunity Name___________________ "> </apex:column> <apex:column Value="{!op.OS_Number__c}" headerValue=" OS Number"> </apex:column> <apex:column Value="{!op.Account.Name}" headerValue="Account Name______________________________________ "> </apex:column> <apex:column Value="{!op.Joint_Proposal__c}" headerValue="Joined Proposal____________________________________________________________"> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Custom Button:
OSNum_wrk = OSNum[0].OS_Number__c;
All Answers
1. Display list on vf page
1.1 VF Page:
<apex:page Controller="JoinedProposalCheckController" showHeader="true" sidebar="false" tabStyle="Opportunity" action="{!Init}">
<apex:form id="JPForm">
1.2 Apex code, add new method Init.
public void Init() {
populateOSNum();
populateOpptyList();
}
1.3 in Apex code, remove method from construct.
public JoinedProposalCheckController() {
populateOSNum();populateOpptyList();
}
2. Add save button
2.1 VF Page, add inside <apex:pageBlock> section
<apex:pageBlock title="Opportunities List" >
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
.....
2.2. Apex:
Add new method Save
public void Save()
{
Update opptyList ;
}
Hi David,
Thank you for the advice, however I need the "button" to be on the Opportutnity Page not my JoinedProposalCheck VFP.
While I have your attention can you help me with query?
I build a string variable OSNum_wrk ( OSNum_wrk = '\''+OSNum[0].OS_Number__c+'\''; ) and displays correctly with System.Debug as '44831'.
When I use OSNum_Wrk in my WHERE statement functions like it's Null? (Commented out below) When I use Literal '44831' I get the desired results.
Any ideas?
OSNum_wrk = OSNum[0].OS_Number__c;