• singledot
  • NEWBIE
  • 50 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies

Hi. I'm facing what seems like it would be an easy fix. I have some open rollup code (Copyright (c) 2012 tgerm.com) that mimics that rollup function on a lookup object (If you need the Apex class it calls I can append it). My "child" object Milestones__c however has two different "master/parent" objects: Goal__c and Class__c. I'm finding that when there is no Goal__c object set (and the child object is only related to Class__c) I'm getting this error:

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger MilestoneRollup caused an unexpected exception, contact your administrator: MilestoneRollup: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.MilestoneRollup: line 67, column 1

 

Basically I just need to limit this trigger to only update when a certain field condition is met - when Milestones__c.Goal_Name__c != NULL. I'm very new to this and I've read this might need a try-catch (see:http://boards.developerforce.com/t5/Apex-Code-Development/Conditional-Trigger/m-p/538539#M97783), but I've tried different iterations and can't seem to get it to work. Here is the trigger with no conditions.

 

trigger MilestoneRollup on Milestones__c (after insert, after update
                                            ) {
      // modified objects whose parent records should be updated
     Milestones__c[] objects = null;   
     
     if (Trigger.isDelete) {
         objects = Trigger.old;
     } else {
        /*
            Handle any filtering required, specially on Trigger.isUpdate event. If the rolled up fields
            are not changed, then please make sure you skip the rollup operation.
            We are not adding that for sake of similicity of this illustration.
        */
        objects = Trigger.new;
     }


     /*
      First step is to create a context for LREngine, by specifying parent and child objects and
      lookup relationship field name
     */

     
     LREngine.Context ctx = new LREngine.Context(Goal__c.SobjectType, // parent object
                                            Milestones__c.SobjectType,  // child object
                                            Schema.SObjectType.Milestones__c.fields.Goal_Name__c  // relationship field name
                                            );
       
     /*
      Next, one can add multiple rollup fields on the above relationship.
      Here specify
       1. The field to which aggregated value will be saved in master/parent object
       2. The field to aggregate in child object
       3. The aggregate operation to be done i.e. SUM, AVG, COUNT, MIN/MAX
     */
     ctx.add(
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Number_of_Related_Milestones_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Number_for_LREngine__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                         
     ctx.add(
                                         
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Milestones_Closed_Not_Completed_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Closed_Not_Completed__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                         
     ctx.add(
            
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Number_of_Milestones_Complete_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Milestones_Complete__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                    

     /*
      Calling rollup method returns in memory master objects with aggregated values in them.
      Please note these master records are not persisted back, so that client gets a chance
      to post process them after rollup
      */
     Sobject[] masters = LREngine.rollUp(ctx, objects);    

     // Persiste the changes in master
     update masters;

    
}

 

 

 

Just trying to do a simple field update on a related object from another object.

trigger UpdateMilestoneStatus on Assessment__c (after insert, after update){


  Set<ID> mileId = new Set<ID>();
  date mileDate;



  for(Assessment__c a : Trigger.new){
    if (a.Passed_Milestone__c == true){
      mileId.add(a.Related_Milestone__c);
      mileDate = a.Test_Date__c;
      
      

    }
}

  List<Milestones__c> mileList = [SELECT id, Status__c, Actual_Completion_Date__c FROM Milestones__c WHERE id in :mileId ];
  for(integer i = 0 ; i < mileList.size(); i++){
    mileList[i].Status__c = 'Complete';
    mileList[i].Actual_Completion_Date__c = mileDate;

   
    
    }
  


  update mileList;
}

 Think the Trigger is okay but really new to testing and completely confused. All of the fields below as necessary fields due to validations/ lookups/ master-detail. 

 

 

@isTest

private class TestClassChangeMilestoneStatus { 

    static testMethod void validateUpdateMilestoneStatus() {   
    
    
      Contact testContact = new Contact( LastName = 'NewContact' );
      insert testContact;
      testContact = [select Id from Contact where Id = :testContact.Id];
      
      
      Milestones__c testMilestone = new Milestones__c( Name = 'Milestone Test', Anticipated_Completion_Date__c =Date.today(), 
                  Related_to_an_Assessment__c = True, Contact_Name__c = testContact.Id, Status__c = 'In Progress' );
      insert testMilestone;
      testMilestone = [select Id from Milestones__c where Id = :testMilestone.Id];
     
      
      Id rtId = [select Id from RecordType where name='TABE 10 Mathematics Computation' and SObjectType='Assessment__c' limit 1].Id;
     

       Assessment__c a = new Assessment__c(
       
        Contact_Name__c= testContact.ID,
        RecordTypeId = rtId,
        Test_Date__c = Date.today(),
        Total_Score__c = 30,
        Passed_Milestone__c = True,
        Related_Milestone__c = testMilestone.ID); 

        insert a;
        }
}

 Any help would be deeply appreciated! L

I've read a couple of similar questions on this board regarding triggers.

Right now, learning Apex, I'm trying to have an event fire from a custom object that has certain "tasks" assigned to a certain user. When a task field is assigned to a user through a lookup field, the trigger ideally would fire an event to that user. What I'm finding is that the trigger is firing everytime the record is saved. I DO need the trigger to fire if the field is just be assigned (so as an update) but once the field is assigned and the event created, I don't need multiple events.

 

This is what I did. Which is not working
.

Created this class:

 

public class Recursionblock {
   public static boolean alreadyRan = false;
}

 

 

Created this trigger (with a lot of help from this community):

 

trigger createPreCheckoutEvent on Set_Up_Transition__c (after insert, after update) {

    if (!Recursionblock.alreadyRan) {
    
    Event[] eventList = new Event[0];
    Map<Id,Property__c> addresses = new Map<Id,Property__c>();

// Aggregate
    for(Set_Up_Transition__c suObj:Trigger.new) {
            addresses.put(suObj.Property_Address__c,null);
    }
    
// Query
    addresses.remove(null);
    addresses.putAll([SELECT Id,Name FROM Property__c WHERE Id IN :addresses.keySet()]);

// Update
    for(Set_Up_Transition__c suOBj:Trigger.new) {
        if(suObj.Pre_Check_Out_Communication_2__c != null) {
            eventList.add(
                new Event(
                   OwnerId = suObj.Pre_Check_Out_Communication_2__c,
                   Subject = 'Pre Check Out Communication',
                   DurationInMinutes = 60,
                   StartDateTime = suObj.Pre_Check_Out_Communication_Time__c,
                   Location = addresses.containsKey(suObj.Property_Address__c)?addresses.get(suObj.Property_Address__c).Name:''));
        }
    }
    insert eventList;
    Recursionblock.alreadyRan = true;
    }
}

 

 

Needless to say, the trigger is still firing every time I save the record.

Hi. I'm looking to assign an Event.Location to a particular lookup relationship field from an object: 

 

 

trigger createPreCheckOutEvent on Set_Up_Transition__c (after insert, after update)
{
    Event[] eventList = new Event[]{};
    
    for (Set_Up_Transition__c suObj:Trigger.new){   
    
    if(suObj.Pre_Check_Out_Communication_2__c != null){
         
        Event evtobj = new Event();
        evtobj.OwnerId = suObj.Pre_Check_Out_Communication_2__c;
        evtobj.Subject = 'Pre Check Out Communication';
        evtobj.DurationInMinutes = 60;
        evtobj.StartDateTime = suObj.Pre_Check_Out_Communication_Time__c;
        evtobj.Location = suObj.Property_Address__r.Name;
        eventList.add(evtObj);
        }
       
    }
    
    insert eventList;
}

 

 

 

 

Basically, I'm new and discovering that the reference field I'm defining (suObj.Property_Address__r.Name) will be null unless I explicitly query for fields on the related record on my custom object (here, the Property_Address__r is in reference to the object Property__c). I'm completely at a loss for how to do this. Any help would be appreciated. Thanks

Hi. I'm just trying to do a simple trigger but I'm experiencing a lot of frustration with how to actually access reference fields. I'm just triggering the creation of an Event from a custom object insert. Basically, in the custom object Set_Up, there is a lookup field (Pre_Communication__r) that is tied to Users...I'd like that specific user to be assigned the event (i.e. not the current user, etc.). This is what I have:

 

trigger createEvent on laniangela__Set_Up__c (after insert) {
         
       for (laniangela__Set_Up__c suObj:Trigger.new){     
  
             Event evtobj = new Event();
             evtobj.Owner = suObj.Pre_Communication__r;
             evtobj.Subject = 'Pre Communication EVENT';
             evtobj.DurationInMinutes = 60;
             evtobj.StartDateTime = suObj.Pre_Communication_Date__c;
             insert(evtobj);
             
  }
}

 

This is clearly not working. This is the error I receive: Error: Compile Error: Illegal assignment from SOBJECT:User to SOBJECT:Name at line 7 column 14 I'm sure it's something ridiculously easy but I'd really love a pointer here. THANK YOU

Hi. I'm facing what seems like it would be an easy fix. I have some open rollup code (Copyright (c) 2012 tgerm.com) that mimics that rollup function on a lookup object (If you need the Apex class it calls I can append it). My "child" object Milestones__c however has two different "master/parent" objects: Goal__c and Class__c. I'm finding that when there is no Goal__c object set (and the child object is only related to Class__c) I'm getting this error:

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger MilestoneRollup caused an unexpected exception, contact your administrator: MilestoneRollup: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.MilestoneRollup: line 67, column 1

 

Basically I just need to limit this trigger to only update when a certain field condition is met - when Milestones__c.Goal_Name__c != NULL. I'm very new to this and I've read this might need a try-catch (see:http://boards.developerforce.com/t5/Apex-Code-Development/Conditional-Trigger/m-p/538539#M97783), but I've tried different iterations and can't seem to get it to work. Here is the trigger with no conditions.

 

trigger MilestoneRollup on Milestones__c (after insert, after update
                                            ) {
      // modified objects whose parent records should be updated
     Milestones__c[] objects = null;   
     
     if (Trigger.isDelete) {
         objects = Trigger.old;
     } else {
        /*
            Handle any filtering required, specially on Trigger.isUpdate event. If the rolled up fields
            are not changed, then please make sure you skip the rollup operation.
            We are not adding that for sake of similicity of this illustration.
        */
        objects = Trigger.new;
     }


     /*
      First step is to create a context for LREngine, by specifying parent and child objects and
      lookup relationship field name
     */

     
     LREngine.Context ctx = new LREngine.Context(Goal__c.SobjectType, // parent object
                                            Milestones__c.SobjectType,  // child object
                                            Schema.SObjectType.Milestones__c.fields.Goal_Name__c  // relationship field name
                                            );
       
     /*
      Next, one can add multiple rollup fields on the above relationship.
      Here specify
       1. The field to which aggregated value will be saved in master/parent object
       2. The field to aggregate in child object
       3. The aggregate operation to be done i.e. SUM, AVG, COUNT, MIN/MAX
     */
     ctx.add(
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Number_of_Related_Milestones_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Number_for_LREngine__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                         
     ctx.add(
                                         
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Milestones_Closed_Not_Completed_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Closed_Not_Completed__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                         
     ctx.add(
            
            new LREngine.RollupSummaryField(Schema.SObjectType.Goal__c.fields.Number_of_Milestones_Complete_Rollup__c,
                                            Schema.SObjectType.Milestones__c.fields.Milestones_Complete__c,
                                            LREngine.RollupOperation.Sum
                                         ));
                                    

     /*
      Calling rollup method returns in memory master objects with aggregated values in them.
      Please note these master records are not persisted back, so that client gets a chance
      to post process them after rollup
      */
     Sobject[] masters = LREngine.rollUp(ctx, objects);    

     // Persiste the changes in master
     update masters;

    
}

 

 

 

Just trying to do a simple field update on a related object from another object.

trigger UpdateMilestoneStatus on Assessment__c (after insert, after update){


  Set<ID> mileId = new Set<ID>();
  date mileDate;



  for(Assessment__c a : Trigger.new){
    if (a.Passed_Milestone__c == true){
      mileId.add(a.Related_Milestone__c);
      mileDate = a.Test_Date__c;
      
      

    }
}

  List<Milestones__c> mileList = [SELECT id, Status__c, Actual_Completion_Date__c FROM Milestones__c WHERE id in :mileId ];
  for(integer i = 0 ; i < mileList.size(); i++){
    mileList[i].Status__c = 'Complete';
    mileList[i].Actual_Completion_Date__c = mileDate;

   
    
    }
  


  update mileList;
}

 Think the Trigger is okay but really new to testing and completely confused. All of the fields below as necessary fields due to validations/ lookups/ master-detail. 

 

 

@isTest

private class TestClassChangeMilestoneStatus { 

    static testMethod void validateUpdateMilestoneStatus() {   
    
    
      Contact testContact = new Contact( LastName = 'NewContact' );
      insert testContact;
      testContact = [select Id from Contact where Id = :testContact.Id];
      
      
      Milestones__c testMilestone = new Milestones__c( Name = 'Milestone Test', Anticipated_Completion_Date__c =Date.today(), 
                  Related_to_an_Assessment__c = True, Contact_Name__c = testContact.Id, Status__c = 'In Progress' );
      insert testMilestone;
      testMilestone = [select Id from Milestones__c where Id = :testMilestone.Id];
     
      
      Id rtId = [select Id from RecordType where name='TABE 10 Mathematics Computation' and SObjectType='Assessment__c' limit 1].Id;
     

       Assessment__c a = new Assessment__c(
       
        Contact_Name__c= testContact.ID,
        RecordTypeId = rtId,
        Test_Date__c = Date.today(),
        Total_Score__c = 30,
        Passed_Milestone__c = True,
        Related_Milestone__c = testMilestone.ID); 

        insert a;
        }
}

 Any help would be deeply appreciated! L

I've read a couple of similar questions on this board regarding triggers.

Right now, learning Apex, I'm trying to have an event fire from a custom object that has certain "tasks" assigned to a certain user. When a task field is assigned to a user through a lookup field, the trigger ideally would fire an event to that user. What I'm finding is that the trigger is firing everytime the record is saved. I DO need the trigger to fire if the field is just be assigned (so as an update) but once the field is assigned and the event created, I don't need multiple events.

 

This is what I did. Which is not working
.

Created this class:

 

public class Recursionblock {
   public static boolean alreadyRan = false;
}

 

 

Created this trigger (with a lot of help from this community):

 

trigger createPreCheckoutEvent on Set_Up_Transition__c (after insert, after update) {

    if (!Recursionblock.alreadyRan) {
    
    Event[] eventList = new Event[0];
    Map<Id,Property__c> addresses = new Map<Id,Property__c>();

// Aggregate
    for(Set_Up_Transition__c suObj:Trigger.new) {
            addresses.put(suObj.Property_Address__c,null);
    }
    
// Query
    addresses.remove(null);
    addresses.putAll([SELECT Id,Name FROM Property__c WHERE Id IN :addresses.keySet()]);

// Update
    for(Set_Up_Transition__c suOBj:Trigger.new) {
        if(suObj.Pre_Check_Out_Communication_2__c != null) {
            eventList.add(
                new Event(
                   OwnerId = suObj.Pre_Check_Out_Communication_2__c,
                   Subject = 'Pre Check Out Communication',
                   DurationInMinutes = 60,
                   StartDateTime = suObj.Pre_Check_Out_Communication_Time__c,
                   Location = addresses.containsKey(suObj.Property_Address__c)?addresses.get(suObj.Property_Address__c).Name:''));
        }
    }
    insert eventList;
    Recursionblock.alreadyRan = true;
    }
}

 

 

Needless to say, the trigger is still firing every time I save the record.

Hi. I'm looking to assign an Event.Location to a particular lookup relationship field from an object: 

 

 

trigger createPreCheckOutEvent on Set_Up_Transition__c (after insert, after update)
{
    Event[] eventList = new Event[]{};
    
    for (Set_Up_Transition__c suObj:Trigger.new){   
    
    if(suObj.Pre_Check_Out_Communication_2__c != null){
         
        Event evtobj = new Event();
        evtobj.OwnerId = suObj.Pre_Check_Out_Communication_2__c;
        evtobj.Subject = 'Pre Check Out Communication';
        evtobj.DurationInMinutes = 60;
        evtobj.StartDateTime = suObj.Pre_Check_Out_Communication_Time__c;
        evtobj.Location = suObj.Property_Address__r.Name;
        eventList.add(evtObj);
        }
       
    }
    
    insert eventList;
}

 

 

 

 

Basically, I'm new and discovering that the reference field I'm defining (suObj.Property_Address__r.Name) will be null unless I explicitly query for fields on the related record on my custom object (here, the Property_Address__r is in reference to the object Property__c). I'm completely at a loss for how to do this. Any help would be appreciated. Thanks