• jlim
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 9
    Replies

We have an issue where we update our pricebook once a year, but we do not want to maintain multiple pricebooks. The problem is when we update the list price, Salesforce goes thru all our opportunities and updates all the List Price. The problem is we already have a trigger that calculates discount and sale price based on List Price. So, once the List Price is updated, unless the user edits the existing opportunity line items, the discount and sale price calculation is incorrect.

 

However, we only want the re-calc to be performed for any open Opportunities and ignore closed ones. So, we created a custom List Price field and I set the formula to be equals to List Price if null, or if not null, then set it to List Price if stage is not "Closed xxx". Otherwise, I want it to be set back to itself or not changed.

 

However, if I do:

 

IF(

  ISNULL(List_Price__c), ListPrice,

  IF(

    CONTAINS(TEXT(Opportunity.StageName),"Closed"), List_Price__c,

    ListPrice

  )

)

 

I'm getting the "Formula cannot use another formula field that directly or indirectly refers to itself".

 

I also tried setting up List_Price__c as just a currency field and use workflow rules to populate the value. This works, except for existing records it is null, unless I edit and save any part of the opportunity line item. If I set it as formula (say a simple List_Price__c = ListPrice), then by virtue of viewing the Opportunity Line Item, the List_Price__c value is populated.

 

I guess I could do a mass update of all the existing Opportunity line items on the backend and then use the workflow rule from now on, but since I'm learning how best to maximize Salesforce functionality, I'm wondering if anyone knows of a way to solve this formula issue?

 

In any programming language, I can just do the following:

 

List_Price__c = List_Price__c == null ? ListPrice : List_Price__c

 

Thanks.

  

Hi,

  Can someone explain how to solve this? On the opportunity line item level, there are 2 standard fields called "List Price" and "Sales Price" defined as Currency(16,2). We have a custom field called Discount__c defined as Percent(12,6).

 

  We have a trigger that will calculate Sales Price or Discount depending on which is changed. The following example shows the results obtained on the sandbox environment.

 

  List Price = 4.75

  Discount = 50%

 

results in Sales Price of 2.38 (Displayed) or 2.375 (stored)

 

  List Price = 4.75

  Sales Price = 2.375 (entered)

 

upon saving,

 

  Sales Price = 2.38 (displayed and stored) and Discount = 49.894737%

 

My question is, if Sales Price is already defined as 16,2 why is the value stored with 3 decimal (2.375)? Ideally we'll need 3 or more precision.

 

Thank you.

 

 

EDIT:

This is really weird and causing our trigger to not work as expected. In our trigger, we compare the old Sales Price and Discount in a loop and depending on what changed, we calculate either new Sales Price or Discount.

 

The IF statement:

 

>> if(Trigger.oldMap.get(oli.id).UnitPrice != oli.UnitPrice && Trigger.oldMap.get(oli.id).Discount__c == oli.Discount__c) {

 

 

What happens is if I change the Sales Price (Unit Price) once, then it calculates a new discount. Now, if I change the Sales Price again without changing the discount values, it thinks the discount is not the same this time around and goes to another loop that calculates Sales Price. I printed out the old and new values the second time and I'm seeing 14 number precision on the old discount as opposed to the set 6 precision.

 

An example of a calculate discount is below:

 

>> 57.89473684210527    57.894737

 

The weirdest part is if I enter 2 then 3 the second time for sales price, I'm seeing 2 and 3 when I print out the variables on another dummy field. But the actual Sales Price field is still showing 2 in the GUI.

 

 

 

What's going on??

Message Edited by jlim on 08-06-2009 03:19 PM

Under Account, I have a custom picklist called Region__c.

Under Opportunity, I have a custom picklist called Sub_Region__c.

 

I want to be able to setup Opportunity.Sub_Region__c picklist to be dependent on the value picked on Account.Region__c.

 

Using the UI, it appears there's no apparent way for me to set up the dependency. If Sub_Region__c is part of Account, then it is possible. But that's not what we want.

 

Can this be done using the UI, or do I need to write a VF page to accomplish this? Thanks.

I'm really new in this and would appreciate any pointers. I read through examples but still not sure how to proceed. TIA.

 

 

/*** Controller ***/
public class MyControllerExtension {

    private final Opportunity oppor;
   

    public myControllerExtension (ApexPages.StandardController stdController) {
        Id id = ApexPages.currentPage().getParameters().get('Id');
       
        oppor = (id == null) ? new Opportunity() :
                [
                 SELECT Id, StageName, Account_Region__c                

                 FROM Opportunity
                 WHERE Id = :id
                ];
    }

 

    public Opportunity getOpportunity() {

        return oppor;

    }

 

   
    public String getButtonState() {
 
        if(oppor.Account_Region__c == 'UK') {
            if(oppor.StageName == 'Closed Won') {
               return 'False';
            } else {
              return 'True';
            }
        } else {
            return 'True';
        }
    }   

}

 

/*** TEST ***/

@isTest
private class TestMyControllerExtension {
  
    static testMethod void TestMyControllerExtension() {
       
        ApexPages.StandardController stdController;
        MyControllerExtension mce = new MyControllerExtension(stdController);
       
        Opportunity oppor = mce.getOpportunity();
 
        oppor.StageName = 'Closed Won';
        oppor.Account.Region__c = 'UK';
         
    
        System.assertEquals(mce.getButtonState(),'False');

    }

}

 

 

Message Edited by jlim on 07-27-2009 02:49 PM

A custom button is laid out on the same level as the standard buttons in our Opportunity detail page, top and bottom. I've a VF page that creates a commandButton that does different things depending on the Opportunity specifics.

 

I would like this VF page to appear at the same level as the standard/custom buttons at the top and bottom of the detail. How do I do it?

 

Right now the only place I can put it is in the detail itself as a field and I cannot "re-use" this VF button more than once on the same page.

 

Thanks.

 Hello All,

 

I have an OpportunityLineItem (oli) before insert trigger that references the oli.ListPrice value.  The trigger works great in my sandbox when manually testing through the UI but is failing due to a null value for oli.ListPrice un unit testing.

 

I have verified that the issue is specifically that the oli.ListPrice value is null when adding the oli through the unit test code, but the ListPrice is not null when adding an oli through the UI.

 

Naturally, I suspected the unit test code had an issue with the PriceBook and PriceBookEntry process.  But after scouring the code, the Apex Code Language Reference section "Testing the Sample Application", and the developer boards, I'm not seeing anything that explains why the oli.ListPrice value would be null in the unit test.

 

The behavior seems like the assignment of the oli.ListPrice from the pbe.UnitPrice isn't happening in the correct sequence when the unit test is running but is occurring correctly when the UI is used.

 

Here is the unit test code that is resulting in a null oli.ListPrice when the oli before insert trigger is firing:



public class testTrigger {
static testMethod void testTriggers_Trigger () {

Product2 p = new product2(name='Test Product');
insert p;

Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
insert new PricebookEntry(pricebook2id = stdPb.id, product2id = p.id, unitprice=100.0, isActive=true);

Pricebook2 pb = new pricebook2(name='test pricebook');
insert pb;

PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=p.id, unitprice=100.0, isActive=true);
insert pbe;

Opportunity o = new Opportunity(name='test', pricebook2id=pb.id, stageName='Open', CloseDate=Date.newInstance(2009,10,10) );
insert o;

OpportunityLineItem oli = new OpportunityLineItem(opportunityid=o.id, UnitPrice=100, quantity=1, pricebookentryid=pbe.Id);
insert oli;

}
}

 

 

I hope that you read this post and chuckle as you gently explain the obvious piece that I'm missing.  Otherwise, any input is appreciated.

 

Cheers,

-Philip 

 

 


 

Message Edited by Philip_F on 03-01-2009 06:01 PM
Message Edited by Philip_F on 03-01-2009 06:02 PM