You need to sign in to do that
Don't have an account?
jmarinchak
My first visualforce attempt
I'm trying to write a short commission calculation page that takes all opportunities and calculates a commission amount based on users quota and variable salary. The variable salary and quota should be multiplied together to determine a commission "rate." The user should navigate to the page, enter their numbers (I could probably store these somplace) and they would get a list of their opportunities, the opportunity amount and a commission amount. It would also be nice to have the total commission amount listed at the end.
If I can get this basic idea working, I would add a few things -
* Date selector - allowing the user to select a date rage (start and end)
* Account selector - allowing the user to select accounts to include (a checkbox approach might work here)
* Group the results by account, show subtotals for each account
* Provide a PDF generation (commission statement)
I got a skeleton of the idea put together but, it isn't really working. I've got a few problems with this code. The page will render but, I the error below when I press calculate. I'm also trying to figure out how to capture a number in the inputfield. This code is using inputext but, I'm really trying to capture number (currency amount) - so I can't use the input values yet and I've just hard coded 10% commission. How should I capture this amount? Should I create a custom currency object just to capture the number?
System.NullPointerException: Attempt to de-reference a null object
Class.ACommissionController.cOpportunity.<init>: line 15, column 33
Class.ACommissionController.getMyList: line 29, column 28
External entry point
Class.ACommissionController.getMyList: line 29, column 28
External entry point
Thanks in advance for any help you can provide!
Jeff
Apex Page:
Controller:
Code:
<apex:page controller="ACommissionController"> <apex:form > <apex:pageBlock title="Inputs"> <p><b>Report for {!$User.FirstName} {!$User.LastName}</b></p> <br /> <b>Quota </b> <apex:inputText value="{!Quota}" /> <br /> <b>Variable Salary </b> <apex:inputText value="{!Variable_Salary}" /> <br /><br /> <apex:commandButton action="{!getMyList}" value="Calculate" rerender="MyOpps" status="status"/> <br /> <apex:pageMessages ></apex:pageMessages> </apex:pageBlock> <apex:actionStatus startText="Updating..." id="status"/> <apex:pageBlock title="MyOpps" > <apex:dataTable value="{!MyList}" var="aOpp" width="100%"> <apex:column > <apex:facet name="header"><b>AccountId</b></apex:facet> {!aOpp.myopp.Id} </apex:column> <apex:column > <apex:facet name="header"><b>Name</b></apex:facet> {!aOpp.myopp.Name} </apex:column> <apex:column > <apex:facet name="header"><b>Amount</b></apex:facet> {!aOpp.myopp.Amount} </apex:column> <apex:column > <apex:facet name="header"><b>Commission</b></apex:facet> {!aOpp.Commission_Amount} </apex:column> </apex:dataTable> </apex:pageBlock> </apex:form> </apex:page>
Controller:
Code:
public class ACommissionController { public string Quota {get; set;} public string Variable_Salary {get; set;} /* New wrapper class */ public class cOpportunity{ public Opportunity myopp {get; set;} public Double Commission_Amount{get; set;} /*This is the constructor method. When we create a new cCommission object we pass a SCRB_Salesorder_c that is set to the corder property. We also set the Commission_Amount value to zero*/ public cOpportunity(Opportunity o){ myopp = o; Commission_Amount = o.Amount * 0.10; } } //A collection of the class/wrapper objects cOpportunity public List<cOpportunity> MyList {get; set;} //This method uses a SOQL query to return a List of Opportunities public List<cOpportunity> getMyList(){ if(MyList == null){ MyList = new List<cOpportunity>(); } for(Opportunity opp : [Select Id, Name, Amount FROM Opportunity ]){ /* As each opportunity is processed I create a new cOpportunity object and add it to MyList */ MyList.add(new cOpportunity(opp)); } return MyList; } }
All Answers
Class.ACommissionController.bMyList: line 35, column 28
Class.ACommissionController.genMyList: line 4, column 18
External entry point
That could be causing the error, and would be a good thing to test for in the wrapper class code.