• Ryno Lourens
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies

I'm trying to build a controller extension for the Opportunity Standard Controller, along with a Visualforce page that  pullsa method from that extension. However, when I try to save the Visualforce page I receive the error: "Unknown function ProductRate. Check spelling."

Here is the Controller Extension:

public class TestClass {
    private final Opportunity opp;

    public TestClass(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    public String getProductRate() {
        return 'rate';
    }
}


And here is the Visualforce page:

<apex:page standardController="Opportunity" extensions="TestClass">
     <apex:outputText value="{!ProductRate()}"/>
</apex:page>

I'm completely at a loss about why the Visualforce page won't access the ProductRate method! Please help!

Hi everyone,

I do a lot of work that involves the Opportunity object, along with the attached Price Book, Product, and Opportunity Product objects.

Because these objects and their relationships can get kind of complicated (especially creating standard and custom Price Book entries for each Product before creating an Opportunity Product), I want to create an Apex Class that will generate this data when needed. That way I can call the necessary data whenever I run a new test, instead of adding that code into each new Apex test class I create.


This is what I have so far, but I'm unsure if I'm on the right track:

@isTest
public class OpportunityDataGenerator {
    
    // create test data
    @testSetup public static void createOpportunityData() {
        // create standard price book
        Pricebook2 stdPricebook = new Pricebook2(
            Name = 'Standard Price Book', 
            IsActive = true
        );
        insert stdPricebook;
        
        // create custom price book
        Pricebook2 customPricebook = new Pricebook2(
            Name = 'Custom Price Book', 
            IsActive = true
        );
        insert customPricebook;
        
        // create product with standard price book and custom price book entries
        Product2 product = new Product2(
            Name = 'Test Product',
            ProductCode = 'TEST001',
            IsActive = true
        );
        insert product;
        
        // add standard price book entry for the product
        PricebookEntry stdPricebookEntry = new PricebookEntry(
            Pricebook2Id = stdPricebook.Id,
            Product2Id = product.Id,
            UnitPrice = 100.0,
            IsActive = true
        );
        insert stdPricebookEntry;
        
        // add custom price book entry for the product
        PricebookEntry customPricebookEntry = new PricebookEntry(
            Pricebook2Id = customPricebook.Id,
            Product2Id = product.Id,
            UnitPrice = 150.0,
            IsActive = true
        );
        insert customPricebookEntry;
        
        // create account with Client_Type__c field
        Account account = new Account(
            Name = 'Test Account',
            Client_Type__c = 'Associate'
        );
        insert account;
        
        // create opportunity related to the account
        Opportunity opportunity = new Opportunity(
            Name = 'Test Opportunity',
            StageName = 'Prospecting',
            CloseDate = Date.today(),
            AccountId = account.Id
        );
        insert opportunity;
        
        // create opportunity product related to the opportunity and the product
        OpportunityLineItem opportunityProduct = new OpportunityLineItem(
            OpportunityId = opportunity.Id,
            PricebookEntryId = customPricebookEntry.Id,
            Quantity = 10,
            UnitPrice = customPricebookEntry.UnitPrice
        );
        insert opportunityProduct;
    }
}
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.
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.

I am trying to write an Apex test Class for a Trigger that I want to deploy. However, when I receive the 'duplicate value found' error:

@isTest
private class ProphixFieldsTest {
    static testMethod void testProphixFields() {
        // Create test data
        Opportunity opp = new Opportunity(Name='Test Opp', StageName='Prospecting', CloseDate=System.today().addDays(30), ForecastCategoryName='Pipeline');
        insert opp;
        Product2 prod = new Product2(Name='Test Product', ProductCode='123', Budget_Code__c='327 - RPD');
        insert prod;
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=opp.Id, Product2Id=prod.Id, UnitPrice=100, Start_Date__c=System.today(), End_Date__c=System.today().addDays(30), Fiscal_Months__c=12);
        insert oli;

        // Test insert trigger
        opp = [SELECT Products_opp1__c, Product_Codes__c, Budget_Code__c, Amount, Current_Fiscal_Revenue__c, QuoteBeginDate__c, QuoteEndDate__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(prod.Name, opp.Products_opp1__c);
        System.assertEquals(oli.ProductCode, opp.Product_Codes__c);
        System.assertEquals(oli.Budget_Code__c, opp.Budget_Code__c);
        System.assertEquals(oli.UnitPrice, opp.Amount);
        System.assertEquals(oli.Fiscal_Revenue__c, opp.Current_Fiscal_Revenue__c);
        System.assertEquals(oli.Start_Date__c, opp.QuoteBeginDate__c);
        System.assertEquals(oli.End_Date__c, opp.QuoteEndDate__c);

        // Test update trigger
        prod.Name = 'Test Product Updated';
        update prod;
        opp = [SELECT Products_opp1__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(prod.Name, opp.Products_opp1__c);

        // Test delete trigger
        delete oli;
        opp = [SELECT Products_opp1__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(null, opp.Products_opp1__c);
    }
}

Hi everyone,

I've got two custom fields in the Opportunities Object (Custom_Opp_Field_1__c, Custom_Opp_Field_2__c) that need to be updated with information from a two fields in Opportunity Product Object (Custom_Prod_Field_1__c, Custom_Prod_Field_2__c) whenever a new Opportunity Product is added or edited.

I've never written a Trigger before, so any help is very much appreciated!

Thanks in advance!
Best,
Ryno Lourens

 

I'm trying to build a controller extension for the Opportunity Standard Controller, along with a Visualforce page that  pullsa method from that extension. However, when I try to save the Visualforce page I receive the error: "Unknown function ProductRate. Check spelling."

Here is the Controller Extension:

public class TestClass {
    private final Opportunity opp;

    public TestClass(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    public String getProductRate() {
        return 'rate';
    }
}


And here is the Visualforce page:

<apex:page standardController="Opportunity" extensions="TestClass">
     <apex:outputText value="{!ProductRate()}"/>
</apex:page>

I'm completely at a loss about why the Visualforce page won't access the ProductRate method! Please help!
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.

I am trying to write an Apex test Class for a Trigger that I want to deploy. However, when I receive the 'duplicate value found' error:

@isTest
private class ProphixFieldsTest {
    static testMethod void testProphixFields() {
        // Create test data
        Opportunity opp = new Opportunity(Name='Test Opp', StageName='Prospecting', CloseDate=System.today().addDays(30), ForecastCategoryName='Pipeline');
        insert opp;
        Product2 prod = new Product2(Name='Test Product', ProductCode='123', Budget_Code__c='327 - RPD');
        insert prod;
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=opp.Id, Product2Id=prod.Id, UnitPrice=100, Start_Date__c=System.today(), End_Date__c=System.today().addDays(30), Fiscal_Months__c=12);
        insert oli;

        // Test insert trigger
        opp = [SELECT Products_opp1__c, Product_Codes__c, Budget_Code__c, Amount, Current_Fiscal_Revenue__c, QuoteBeginDate__c, QuoteEndDate__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(prod.Name, opp.Products_opp1__c);
        System.assertEquals(oli.ProductCode, opp.Product_Codes__c);
        System.assertEquals(oli.Budget_Code__c, opp.Budget_Code__c);
        System.assertEquals(oli.UnitPrice, opp.Amount);
        System.assertEquals(oli.Fiscal_Revenue__c, opp.Current_Fiscal_Revenue__c);
        System.assertEquals(oli.Start_Date__c, opp.QuoteBeginDate__c);
        System.assertEquals(oli.End_Date__c, opp.QuoteEndDate__c);

        // Test update trigger
        prod.Name = 'Test Product Updated';
        update prod;
        opp = [SELECT Products_opp1__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(prod.Name, opp.Products_opp1__c);

        // Test delete trigger
        delete oli;
        opp = [SELECT Products_opp1__c FROM Opportunity WHERE Id=:opp.Id];
        System.assertEquals(null, opp.Products_opp1__c);
    }
}