You need to sign in to do that
Don't have an account?
Jason 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'
});
}
}
}
}
}
}
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'
});
}
}
}
}
}
}
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
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' }); } } } }
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.