+ Start a Discussion
TrimbleAgTrimbleAg 

Discount line items from the account level

We have a tier discounting level for our dealers that depends on their sales.

My issue is, I want to create a field on our accounts called "Discount Level" and have it so that any time a product is added to a Opp, that it auto applies the discount level to the line item based on the account that is associated.

Any Suggestion?
 
Thanks,
PB
Best Answer chosen by Admin (Salesforce Developers) 
jhurstjhurst

PB,

 

There are a couple of options (depending on how complex you want to get)

 

1. Add a trigger to the Opportunity Product.  The idea here would be that when the user saved the Opportunity Product, the Trigger would go to the parent Account, pull the discount level, and then apply the discount to the Opportunity Product UnitPrice.  The (un bulkified) code would look like:

 

trigger applyDiscount on OpportunityLineItem (before insert) {
    Id acctId = [select AccountId from Opportunity where id =:Trigger.new[0].OpportunityId].AccountId;
    Account a = [select id, Discount__c from Account where id =:acctId];
    Trigger.new[0].UnitPrice = Trigger.new[0].UnitPrice * (a.Discount__c/100);
}

 2. Replace the Opportunity Product creation page with a VF page.  This is much more complex and would require a design of the Opportunity Price Book selection Page as well as the Opportunity Product Lookup.  The advantage is that you could do a lot more such as to actually display the Account Discount, and allow the user to override the discount.

 

Hope this helps.

Jay 

All Answers

jhurstjhurst

PB,

 

There are a couple of options (depending on how complex you want to get)

 

1. Add a trigger to the Opportunity Product.  The idea here would be that when the user saved the Opportunity Product, the Trigger would go to the parent Account, pull the discount level, and then apply the discount to the Opportunity Product UnitPrice.  The (un bulkified) code would look like:

 

trigger applyDiscount on OpportunityLineItem (before insert) {
    Id acctId = [select AccountId from Opportunity where id =:Trigger.new[0].OpportunityId].AccountId;
    Account a = [select id, Discount__c from Account where id =:acctId];
    Trigger.new[0].UnitPrice = Trigger.new[0].UnitPrice * (a.Discount__c/100);
}

 2. Replace the Opportunity Product creation page with a VF page.  This is much more complex and would require a design of the Opportunity Price Book selection Page as well as the Opportunity Product Lookup.  The advantage is that you could do a lot more such as to actually display the Account Discount, and allow the user to override the discount.

 

Hope this helps.

Jay 

This was selected as the best answer
TrimbleAgTrimbleAg

Hey Jay,

 

I will probally use #1, like you said its the easier method, but like idea #2 design.

 

Thanks for the help!

 

Pat