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
miss vmiss v 

trigger to relate objects

I think I need a trigger to relate two objects, 

i have two custom objects, (Product Info and Revenue)... both are the child object of Account.  

 

In Product Info, I have a picklist of values (Organes, Apples, etc). and then a bunch of price data about each product, including my commission rate.   So if the Account is Trader Joes, Oranges may .59 each.   If the Account is Whole Foods, Oranges may be .69 each. Each accout has about 4 or 5 records depending on what I sell to them.

 

 

In the Revenue Object, I enter Oranges Revenue - $100,000 for May (related by Master Detail to Account - Trader Joes).    That is the amount of revenue Trader Joes earned on Oranges I sold them.

 

Now, I want to write a formula that allows me to calculate the commisions i recieve based on each product for each month's revene.   I wrote this cross object formula for the Revenue Object:

 

IF(ISPICKVAL(Product_Info_r.Product_c., "Oranges"), (Product_Info_r.Commision_Rate_c*Orange Revenue), null)

 

However, the fomula doesn't calculate correctly because when it tries to find the Commission Rate from Product_Info, it doesn't now which Orange picklist value to associate - because there is a different orange commission value under each account page.  

 

I find this odd - consdsidering both are child objects under Account, but this seems to be the problem.   I even tried adding some additional formula that said IF(Product_Info_r.AccountID=Revenue_AccountID....   

 

Is there any way to write an Apex trigger that would associate the two object based on the account they are under?  Is this is even the right way to go about this?

 

 

WhyserWhyser

What if you provided a lookup field in the Revenue Object?

Revenue.Product_Info__c

that will point to the relevant Product Info pricing you're interested in? You will then need to populate the fields yourself though. 

 

That way you can do your formula

Product_Info__r.Commission_Rate__c * Revenue.Revenue_Amount__c (or whatever the field is called)

 

Not sure if this is the best way. Not familiar with your business process so this may not work for you.

 

miss vmiss v
Unfortunately, I've tried that.  Basically when I type "Oranges" in the lookup field, it doesn't know which Account's orange to relate to...  or if i'm search, i have a huge list of oranges (like 35) and i have to pick and choose which account's orange to relate.   Not a huge deal, except for this is updated constantly by many different people, it's cumbersome and error-prone...  :(