1

I have say object A, B and C with A and C as parent object and B as a junction object. What I want is- whenever a B is created between A and C, a field named field__c on A should be transferred to C through some calculation and whenever two instances of C are linked to A then value should be divided in half and likewise if more instances are created then 1/3, 1/4 so on. this I have achieved through trigger. Additionally, what I want is If one instance of C is connected to two A's then the value of field__c from 2nd parent A should get added to already existing value. this is the part where I am stuck!

So, I have to explain through example- If A1 field__c value is 100 and it has C1 instance and C2 instances linked to itself, then value passed would be-

C1 - 50 C2 - 50

But if A2 parent with 50 value on field__c gets attached to C2 as well, then value would be-

C2 - 50+50 = 100

How should I do it? Any help would be appreciated!

1
  • 1
    It would be ideal if you could share the code so that we can share insights. Commented Feb 5, 2022 at 13:04

1 Answer 1

0

Just as you solved the first half of your problem using a trigger, you'll need to do the same using a trigger. The key of course will be keeping track of the A and C record Id's which will require maps so you'll know how many instances of one Object are connected via the junction object to the other. Since I don't know how you implemented the first trigger, it's difficult for me to advise you on the second. You may need to be cautious of recursion that could create a repeated loop your code might get stuck in.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .