Skip to main content
Ryno Lourens (Nlogic) 님이 #Apex에 질문했습니다
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.
답변 4개
  1. 2023년 5월 1일 오후 2:05
    Hi Ryno ,

    I noticed one more thing that In your Visualforce page, you're trying to call the getRate method from your custom controller like this:

     

    <apex:outputText value="{0, number, currency}">

        <apex:param value="{!getRate(item)}"/>

    </apex:outputText>

    However, in your custom controller, the method is actually named GetRate with a capital "G".

    <apex:outputText value="{0, number, currency}">

        <apex:param value="{!GetRate(item)}"/>

    </apex:outputText>

    Can you try this and let me know further .

    Thank you.
0/9000