4

I am trying to write trigger for doing following updation on Call__c object

Call__c is having M-D relationship with account. Account has fields ---------- co-owner field, call_by other_c Co-owner field has userid of all other accounts separated with semi colon. Call_c has fields ----------- updated

This is scenario--- There are 3 Accounts with name ‘Aaron’ which is assigned to 3 users ‘A,B,C’

User---- Account Name ------co-owner----- called by other---Related updated field in call_c
A           Aaron       userid of B and C      22                    14
B           Aaron       userid of A and C      24                    12
C           Aaron       userid of A and B      26                    10

When user ‘B’ logs in and try to update Aaron related “update” field to 8 from 12, call by other field of User ‘A’ should update by summing 10+8=18 and User ‘C’ should update to 14+8=22. When user ‘C’ logs in and try to update Aaron related “update” field to 8 from 10, call by other field of User ‘A’ should update by summing 8+8=16 and user ‘B’ should updated to 14+8=22 . So I am looking to update the call by other field by summing who else called for the same account when there is change in Call object. Below is the trigger

trigger calbyupdate on Call__c (after update) {
    public aggregateresult totvalue;
    for( Call__c CurrentCallstring:trigger.new){   
        List<Account> AccountList = [Select PDE1__c, Total_Calls_Formula__c, 
            called_by_other__c, OwnerId, Co_Owner__c, Name 
            from Account where  name = 'Adam Vargo'];
        List<Account> toUpdateAccList = new List<Account>();
        //user u=[select id from user where id=:userinfo.getuserid()];
        for (account acc:AccountList)
        {
            String s='%' + acc.name+'%'; 
            String str = acc.Co_Owner__c; 
            List<String> sArr = str.split(';', 0);

            totvalue  = [Select SUM(Total_Calls_Formula__c) 
                from account 
                where ownerid!= :acc.Ownerid and name like :s and OwnerId in :sArr ];
            acc.called_by_other__c = Integer.valueOf(totvalue.get('expr0')); 
            toUpdateAccList.add(acc);
        }
        update toUpdateAccList;
    }
}
  • Definitely need some more info here. Your second paragraph When user ‘B’ logs in and try to update Aaron related “update” field to 8 from 12, call by other field of User ‘A’ should update by summing 10+8=18 and User ‘C’ should update to 14+8=22... Needs some serious clarification. Need to really understand the use case to help you with the code. I'm sure we can help you, just need to describe the desired outcome better. – Chris Duncombe Jul 25 '13 at 18:43
  • @Arun SFDC - You've provided a scenario and a trigger, but there is no mention of the current behavior of the trigger, and how this differs from the desired behavior. Could you clarify? – metadaddy Jul 26 '13 at 17:01

Browse other questions tagged or ask your own question.