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
Ryno LourensRyno Lourens 

Calling a new method from a custom controller.

Hi everyone,

I'm creating a Visualforce page that needs to display a specific value from a custom object called Rate Cards. I've created a custom controller with a new method called GetRate that should do the trick, however, when I try to call the GetRate method from the Visualforce page, it says that no such method exists. Please take a look at my two pages and let me know what you think!

Rate Card Test Visualforce Page:
<apex:page standardController="Opportunity" extensions="RateCardCalculations">
    <apex:form >
        <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="oli">
            <apex:pageBlock title="Rate Card - {!Opportunity.Pricebook2.Name}">
                <apex:pageBlockTable value="{!oli}" var="item">
                    <apex:column headerValue="Product Name">
                        <apex:outputLink value="/{!item.Id}">{!item.PricebookEntry.Name}</apex:outputLink>
                    </apex:column>
                    <apex:column headerValue="Product Family">
                        <apex:outputField value="{!item.Product_Family__c}" />
                    </apex:column>
                    <apex:column headerValue="Billings/Type/Market">
                        <apex:inputField value="{!item.Price_Book__c}" style="display:none;"/>
                        <apex:outputField value="{!item.Billing_Type_Market__c}" />
                    </apex:column>
                    <apex:column headerValue="Base Price">
                          <apex:outputText value="{0, number, currency}">
                                  <apex:param value="{!getRate(item)}"/>
                          </apex:outputText>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:repeat>
    </apex:form>
</apex:page>

RateCardCalculations Custom Controller

public class RateCardCalculations {
   	public Opportunity opp;
    
    public RateCardCalculations(ApexPages.StandardController controller) {
        opp = (Opportunity)controller.getRecord();
    }
    
    public Decimal getRate(OpportunityLineItem item) {
    Decimal rate = 0;
    String fieldName = item.Name;
    List<Rate_Card__c> rateCards = [SELECT Name, Product_Family__c, Billings_Type_Market__c, Price_Book__c
                                    FROM Rate_Card__c                                    
                                    WHERE Price_Book__c = :item.Price_Book__c 
                                    AND   Billings_Type_Market__c = :item.Billing_Type_Market__c 
                                    AND   Product_Family__c = :item.Product_Family__c];
    if(rateCards != null && rateCards.size() > 0) {
        for(Rate_Card__c rc : rateCards) {
            SObjectField f = SObjectType.Rate_Card__c.fields.getMap().get(item.PricebookEntry.Product2.Name + '__c');
            if(f != null) {
                rate = (Decimal)rc.get(f);
                break;
            }
        }
    }
    return rate;
	}
}

tl:dr - Please let me know why the Visualforce page won't call the GetRate method from the custom controller.