We have created a Project Template and need to be able to clone it when an opportunity stage changes to Closed Won. I have started a Trigger on the Opportunity object after update that checks the StageName. I am looking for a code sample or documentation on what to call to clone the project template we have, name it according to the Opportunity Name and set a Start Date for today and end date of 30 days from today. I have searched and searched and cannot find any documentation for doing this with Milestones PM. I could use the Import Template process but need some guidance on using this in a trigger. Thanks in advance for any help!

2 Answers 2


I found a developerforce post Connect Milestones PM to your Objects. You can also look at the github repo for Milestones PM.

You can actually view the source of the Template Import Page directly in your org or by looking at the github repo.

The Milestone1_Import_Project_Controller class calls to the Milestone1_XML_Import_Utility importUtility.importProject method. I also see that there is a Milestone1_Clone_Utility that might be useful.

The only catch is that you'll have to write your Trigger to handle bulk updates and inserts, so you might have to adapt the utility classes and implementations to make sure you don't have DML or SOQL in for loops.

Apex provides a clone method for sObjects that might be useful for you as well.


Check out Milestones PM+, a managed package https://appexchange.salesforce.com/listingDetail?listingId=a0N30000009uYYMEA2

We built a method you can use to interface with the import process.

The structure of the trigger you will use goes like this:

trigger MPM4_Your_Object_Name on Your_Object_Name__c (after insert, after update) {

 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();

projCreationUtil.CreateChildProject(trigger.oldMap, trigger.newMap, new Map<string, object>{
'projectCreationField' => 'Field_Determining_Template_To_Use__c', 
'projectLookupField1' => 'Primary_Lookup_Field_On_Project__c',
'projectLookupField2' => 'Second_Lookup_Field_On_Project__c', 'secondaryLookup' => 'Secondary_Source_Lookup_Field__c',  'projectNamingConventionField' => 'Project_Naming_Convetion__c'});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.