You need to sign in to do that
Don't have an account?
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?
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.