• Warren Wade, AE
  • NEWBIE
  • 20 Points
  • Member since 2017
  • Solutions Architect
  • Acutedge


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
'm working on a trigger for an org I do some volunteering for and I'm stuck (because I'm not good at this).  
Preservation_Object__c is the Master object and Preservation_Activities__c is the child account

It's supposed to update the parent object with the Activity_Type__c of most recent Activity_Date__c

When the Child record is updated or inserted, it works like it's supposed to.

With the trigger.isdelete added, I'm getting an "Attempt to de-reference a null object" error at line 5. 

Any thoughts on how this could get fixed?
trigger RollUpRecentActivity on Preservation_Activities__c (after insert, after update, before delete) {
    set<Id>setPreserveId = new set<Id>(); 
    list<Preservation_Object__c>listPreserve = new list<Preservation_Object__c>(); 
    if(trigger.isInsert || trigger.isUpdate || trigger.isdelete){
        for(Preservation_Activities__c oActivities:trigger.new){ 
            setPreserveId.add(oActivities.Preservation_Object__c); 
        }
    }
    system.debug('@developer-->setPreserveId: '+setPreserveId);
    if(setPreserveId.size()>0){ 
        for(Preservation_Activities__c oActivities:[
            Select Preservation_Object__c,id,Name,Activity_Type__c,Activity_Date__c  
            from Preservation_Activities__c 
            where Preservation_Object__c In:setPreserveId and Activity_Date__c != null and isDeleted = FALSE
            order by Activity_Date__c desc limit 1]){
                Preservation_Object__c oPreserve = new Preservation_Object__c();
                oPreserve.Id = oActivities.Preservation_Object__c;
                oPreserve.Last_Activity_Type__c = oActivities.Activity_Type__c;
                listPreserve.add(oPreserve);
            }
        system.debug('@developer-->listPreserve: '+listPreserve); 
        if(listPreserve.size()>0){ 
            update listPreserve;
        }
    }
}

 
When a Preservation Activity (child) gets deleted, I need the Preservation Object (parent) to recalculate the Max Date.
(also, I'm not a coder so I tried to annotate what I thought was happening in the code that's why those notes are there.)
trigger RollUpRecentActivity on Preservation_Activities__c (after insert, after update, after delete) {
    set<Id>setPreserveId = new set<Id>(); //set new variable "setPreserveID"
    list<Preservation_Object__c>lstPreserve = new list<Preservation_Object__c>(); //set a new Preservation Object list called "lstPreserve"
    if(trigger.isAfter){ //if it's afterUpdate
        system.debug('@Developer --> isAfter:'); //debug statement
        if(trigger.isInsert || trigger.isUpdate){ //if it's on insert OR update
            for(Preservation_Activities__c oActivities:trigger.new){ //set oActivities which equals the activity/ies that are trigger.new
                setPreserveId.add(oActivities.Preservation_Object__c);//to the setPreserveId variable, add the PReservation objects of the activities in the trigger
            }
        }
        system.debug('@developer-->setPreserveId: '+setPreserveId);  //debug statement
        if(setPreserveId.size()>0){ //if there's actually an id
        for(Preservation_Activities__c oActivities:[
            	Select Preservation_Object__c,id,Name,Activity_Type__c,Activity_Date__c  
            	from Preservation_Activities__c 
            	where Preservation_Object__c In:setPreserveId and Activity_Date__c != null and isDeleted = FALSE
            	order by Activity_Date__c desc limit 1]){
            Preservation_Object__c oPreserve = new Preservation_Object__c();
            oPreserve.Id = oActivities.Preservation_Object__c;
            oPreserve.Last_Activity_Type__c = oActivities.Activity_Type__c;
            lstPreserve.add(oPreserve);
        }
        system.debug('@developer-->lstPreserve: '+lstPreserve);
        if(lstPreserve.size()>0){
            update lstPreserve;
        }
        }
    }
 }

 
I think I've exhausted my declarative means to get this info (native features, Process Builder and Flow) and I'm not a programmer so I'm reaching out.
  • I have a two objects: Preserve__c (Master) and Activities__c (Detail). 
  • The Activities__c object has two pertinent fields: Date__c & Type__c.
  • On Preserve__c, I have a field Most_Recent_Activity_Type__c.
  • I need to roll the Type__c of the most recent Activity record to the Preserve record to that field.
Example
  1. Type = Walk, Date = 1/1/2017
  2. Type = Run, Date = 6/1/2017
  3. Type = Fly, Date = 9/1/2017
Most Recent Activity = Fly

Help!
With Analytics rounding, a component could have a 77.9 value, correctly assign it to the min bar but display a rounded up number.  How can I get the decimals to display in a gauge like the one below?  
User-added image
When a Preservation Activity (child) gets deleted, I need the Preservation Object (parent) to recalculate the Max Date.
(also, I'm not a coder so I tried to annotate what I thought was happening in the code that's why those notes are there.)
trigger RollUpRecentActivity on Preservation_Activities__c (after insert, after update, after delete) {
    set<Id>setPreserveId = new set<Id>(); //set new variable "setPreserveID"
    list<Preservation_Object__c>lstPreserve = new list<Preservation_Object__c>(); //set a new Preservation Object list called "lstPreserve"
    if(trigger.isAfter){ //if it's afterUpdate
        system.debug('@Developer --> isAfter:'); //debug statement
        if(trigger.isInsert || trigger.isUpdate){ //if it's on insert OR update
            for(Preservation_Activities__c oActivities:trigger.new){ //set oActivities which equals the activity/ies that are trigger.new
                setPreserveId.add(oActivities.Preservation_Object__c);//to the setPreserveId variable, add the PReservation objects of the activities in the trigger
            }
        }
        system.debug('@developer-->setPreserveId: '+setPreserveId);  //debug statement
        if(setPreserveId.size()>0){ //if there's actually an id
        for(Preservation_Activities__c oActivities:[
            	Select Preservation_Object__c,id,Name,Activity_Type__c,Activity_Date__c  
            	from Preservation_Activities__c 
            	where Preservation_Object__c In:setPreserveId and Activity_Date__c != null and isDeleted = FALSE
            	order by Activity_Date__c desc limit 1]){
            Preservation_Object__c oPreserve = new Preservation_Object__c();
            oPreserve.Id = oActivities.Preservation_Object__c;
            oPreserve.Last_Activity_Type__c = oActivities.Activity_Type__c;
            lstPreserve.add(oPreserve);
        }
        system.debug('@developer-->lstPreserve: '+lstPreserve);
        if(lstPreserve.size()>0){
            update lstPreserve;
        }
        }
    }
 }

 
I think I've exhausted my declarative means to get this info (native features, Process Builder and Flow) and I'm not a programmer so I'm reaching out.
  • I have a two objects: Preserve__c (Master) and Activities__c (Detail). 
  • The Activities__c object has two pertinent fields: Date__c & Type__c.
  • On Preserve__c, I have a field Most_Recent_Activity_Type__c.
  • I need to roll the Type__c of the most recent Activity record to the Preserve record to that field.
Example
  1. Type = Walk, Date = 1/1/2017
  2. Type = Run, Date = 6/1/2017
  3. Type = Fly, Date = 9/1/2017
Most Recent Activity = Fly

Help!