function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jason CorumJason Corum 

Milestones PM+ Object Integration Trigger

Hi! I'm working to integrate Milestones PM+ with a custom object. Essentially, I'm looking for my Apex Trigger to create a Milestones PM+ Project associated with my custom object once a specific status is reached. However, using their admin guide template (http://www.passagetechnology.com/mpm-admin-guide), I'm not able to get the Milestones PM+ Project created "after update." But, it works "after insert." Any thoughts, anyone?

trigger ObjectTrigger on Object__c (after insert, after update) {
    
    if(Trigger.isAfter){

        for (Object__c object : Trigger.new) {
                
                if(object.Status__c == 'Executed') {
                                                                
                Type pcu = System.Type.forName('MPM4_BASE', 'Milestone1_Project_Creation_Utility');
                    
                if(pcu != null) {
        
                    MPM4_BASE.Milestone1_Project_Creation_Utility projCreationUtil = (MPM4_BASE.Milestone1_Project_Creation_Utility) pcu.newInstance();
                        
                    if(Trigger.isAfter){               
                        projCreationUtil.CreateChildProject(trigger.oldMap, trigger.newMap, new Map<string, object>{
                            'projectCreationField' => 'Project_Template__c',
                            'projectLookupField1' => 'Object__c',
                            'projectNamingConventionField' => 'Project_Name__c'
                        });
                    }
                }
            }
        }
    }
}

 
Best Answer chosen by Jason Corum
Jason CorumJason Corum
Thanks for taking a look reidjn! I actually found the issue and solved in my case, but this reminded me that I could help out others who might have this issue by putting the resolution here.

I found the source code for the project on GitHub (https://github.com/PassageTech/Milestones-PM-Plus) and found that "after update" wasn't working for me because CreateChildProject was expecting null for trigger.oldMap in order to make the update. Since my object needs to exist prior to creation I ended up needing to send in a null value for trigger.oldMap.

All Answers

reidjnreidjn
Hi Jason,

After taking another look at this it appears that you have modified the trigger from the example in the admin guide and this could be causing the issue. The project trigger works in the after update context.

Maybe revert back to this example and see if you can get it working again?


trigger MPM4_Your_Object_Name on Your_Object_Name__c (after insert, after update) {
          if(Trigger.isAfter) {
             Type pcu = System.Type.forName('MPM4_BASE', 'Milestone1_Project_Creation_Utility');
              if(pcu != null){
                      MPM4_BASE.Milestone1_Project_Creation_Utility projCreationUtil =               (MPM4_BASE.Milestone1_Project_Creation_Utility)pcu.newInstance();
                      if(Trigger.isAfter){
                           projCreationUtil.CreateChildProject(trigger.oldMap, trigger.newMap, new Map<string, object>{
                                   'projectCreationField',
                                   'projectLookupField1',
                                   'projectLookupField2',
                                   'secondaryLookup',
                                   'projectNamingConventionField' }); } } } }
Jason CorumJason Corum
Thanks for taking a look reidjn! I actually found the issue and solved in my case, but this reminded me that I could help out others who might have this issue by putting the resolution here.

I found the source code for the project on GitHub (https://github.com/PassageTech/Milestones-PM-Plus) and found that "after update" wasn't working for me because CreateChildProject was expecting null for trigger.oldMap in order to make the update. Since my object needs to exist prior to creation I ended up needing to send in a null value for trigger.oldMap.
This was selected as the best answer