• gastonien
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
I have a field on a parent object it need to be the roll up of child field. Just like a roll up sum but this time to add text fields separated by a comma or space
Populate the value of a field on childs object on a parent fields,just like a RollUp count but instead it adds up the field value on a field on the parent field and displays as text field separated by comma or selected multi select picklist. Any idea?
trigger avgofresiduals on child__c (after insert, after update, after delete,after undelete) {

    //Set<ID> ids = Trigger.newMap.keySet();
   
    Set<Id> AcctIds = new Set<Id>();    
    //Set<Id> AcctIds = Trigger.newMap.keySet();    
    
    List<child__c > ConList = new List<child__c >();
    
    if(trigger.isInsert || trigger.isUPdate) {
        for(child__c Con : trigger.New) {
            AcctIds.add(Con.Deal__c);     
        }  
    }
    if(trigger.isDelete || trigger.isUndelete) {
        for(child__c  Con : trigger.Old) {
            AcctIds.add(Con.Deal__c);     
        }  
    }       
    
     Map<Id, List<child__c >> AcctContactList = new Map<Id, List<child__c >>();
     
    ConList = [SELECT Id, Deal__c, Volume__c,
               FROM child__c 
               WHERE Deal__c IN : AcctIds 
               ORDER BY CreatedDate DESC 
               LIMIT 3
               ];
               
   List<deal__c> AcctList = new List<deal__c>();
               
    double j=0;

    for(child__c  Con : ConList) {

            if(con.Volume__c!= null) {
                j += con.Volume__c;
            } 
    
                       
    }    
    AcctList = [SELECT volumesum 
                FROM deal__c
                WHERE Id IN : AcctIds
                ];
    
   
        List<child__c > ContList = new List<child__c >();
        ContList = AcctContactList.get(Acc.Id);
        Acc.volumesum = j;
        
       
    }
    update AcctList;

}
I would like to write a trigger when task is completed and the case (a field) associated to the task send an email, trigger doesnt work when i add a field from a different object different from task:

.customer_Service_Agent__c is on case not task

trigger Notify_task_creator on task (after update) {
task t=[select CreatedBy.email, id, CreatedByid, CreatedBy.name, LastModifiedByid, LastModifiedBy.name, Subject
        from task 
        where id=:trigger.newMap.keySet()];

                        
for (task o : Trigger.new) 
{ 
if((o.Status=='Completed' ) && (o.CreatedByid != o.LastModifiedByid) && (o.CreatedByid != o.customer_Service_Agent__c)){ 

 MailerUtils.sendMail('<html><body>Hi ' + t.CreatedBy.name +', <br><br>' + t.LastModifiedBy.name + ' has completed the task: "' + t.Subject + '" <br><br>Click on this link for more information:</body></html>' + '\n' + 'https://p2-1147--Full.cs11.cloudforce.com/'+o.Id);
    }

} 
}


trigger avgofresiduals on child__c (after insert, after update, after delete,after undelete) {

    //Set<ID> ids = Trigger.newMap.keySet();
   
    Set<Id> AcctIds = new Set<Id>();    
    //Set<Id> AcctIds = Trigger.newMap.keySet();    
    
    List<child__c > ConList = new List<child__c >();
    
    if(trigger.isInsert || trigger.isUPdate) {
        for(child__c Con : trigger.New) {
            AcctIds.add(Con.Deal__c);     
        }  
    }
    if(trigger.isDelete || trigger.isUndelete) {
        for(child__c  Con : trigger.Old) {
            AcctIds.add(Con.Deal__c);     
        }  
    }       
    
     Map<Id, List<child__c >> AcctContactList = new Map<Id, List<child__c >>();
     
    ConList = [SELECT Id, Deal__c, Volume__c,
               FROM child__c 
               WHERE Deal__c IN : AcctIds 
               ORDER BY CreatedDate DESC 
               LIMIT 3
               ];
               
   List<deal__c> AcctList = new List<deal__c>();
               
    double j=0;

    for(child__c  Con : ConList) {

            if(con.Volume__c!= null) {
                j += con.Volume__c;
            } 
    
                       
    }    
    AcctList = [SELECT volumesum 
                FROM deal__c
                WHERE Id IN : AcctIds
                ];
    
   
        List<child__c > ContList = new List<child__c >();
        ContList = AcctContactList.get(Acc.Id);
        Acc.volumesum = j;
        
       
    }
    update AcctList;

}
I would like to write a trigger when task is completed and the case (a field) associated to the task send an email, trigger doesnt work when i add a field from a different object different from task:

.customer_Service_Agent__c is on case not task

trigger Notify_task_creator on task (after update) {
task t=[select CreatedBy.email, id, CreatedByid, CreatedBy.name, LastModifiedByid, LastModifiedBy.name, Subject
        from task 
        where id=:trigger.newMap.keySet()];

                        
for (task o : Trigger.new) 
{ 
if((o.Status=='Completed' ) && (o.CreatedByid != o.LastModifiedByid) && (o.CreatedByid != o.customer_Service_Agent__c)){ 

 MailerUtils.sendMail('<html><body>Hi ' + t.CreatedBy.name +', <br><br>' + t.LastModifiedBy.name + ' has completed the task: "' + t.Subject + '" <br><br>Click on this link for more information:</body></html>' + '\n' + 'https://p2-1147--Full.cs11.cloudforce.com/'+o.Id);
    }

} 
}