function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jmarinchakjmarinchak 

Is it legal to call a function from a constructor method?

I'm getting this error: Error: Compile Error: Method does not exist or incorrect signature: Commission1(Double, Double, Double, Double) at line 27 column 37.

 

 

<apex:page controller="CommishController"> <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="{!genMyList}" value="Calculate" rerender="MyOpps" status="status"/> <br /> <apex:pageMessages ></apex:pageMessages> </apex:pageBlock> <apex:actionStatus startText="Updating..." id="status"/> <apex:pageBlock title="MyOpps" id="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>

 

 

 

 

public class CommishController { public PageReference genMyList() { MyList = bMyList(); return null; } public Double Quota {get; set;} public Double 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,Double Q,Double VS){ myopp = o; if(!(o.Amount==null)){ Double Rate = 0; If (Q > 0) { Rate = VS/Q; } Double myAmount = o.Amount * 1.0; //public Double Commission1(double rev_start, double rev_new, double quota, double rate) { Commission_Amount = Commission1(0.0, myAmount, Q, Rate); }else{ Commission_Amount = 0; } } } //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> bMyList(){ 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,Quota,Variable_Salary)); } } return MyList; } /* This method calculates commission */ public Double Commission1(double rev_start, double rev_new, double quota, double rate) { // Calculates Commission according to the structure below // If the code looks VBA-like, that's because I originally wrote it // as a VBA user defined function back in 2006 // Less than or equal to 100%, 1.0x (calculated based on quota) // Greater than 100% to 150%, 1.5x calculated rate // Greater than 150%, 2.0x calculated rate // Inputs are // REV_START = Revenue at Period Start // REV_NEW = Revenue for the Period // QUOTA = Annual Quota // RATE = Commission Rate Double rev_total; Double c; Double a; Double q150; Double q25; Double myCommish = 0.0; rev_total = rev_start + rev_new; c = rev_total; a = rev_start; q150 = 1.50 * quota; q25 = 0.25 * quota; If (a > q150) { myCommish = 2 * RATE * REV_NEW; } Else { If (A > QUOTA) { If (C > Q150) { myCommish = RATE * ((2 * (C - Q150)) + (1.5 *(Q150 - A))); } Else { myCommish = RATE * 1.5 * (C - A); } } Else { If (C > Q150) { myCommish = RATE * ((2 * (C - Q150)) + (1.5 * Q25 + (QUOTA - A))); } Else { If (C > QUOTA) { myCommish = RATE * ((1.5 * (C - QUOTA)) + (QUOTA - A)); } Else { myCommish = RATE * (C - A); } } } } return myCommish; } }

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

I think the issue is that you are calling the Commission1 function (which is defined in the CommishController class) from within your inner class, cOpportunity. So the scope of the methods are not valid in your code. So you need to either define Commission1 as a static method and call it like CommishController.Commission1() or instantiatiate an instance of CommishController and call the method from that object.

 

-Andrew