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
Randi ThompsonRandi Thompson 

Milestones PM+ Opportunity trigger

Good morning! I'm hoping someone here can help me finish the sample Opportunity trigger that comes with the Milestones PM+ implementation guide. I'm not sure why I can't use a Lookup field to the Opportunity, as the guide says that's acceptable for creating projects from Accounts, but I'm just following instructions. The provided code is below and I've bolded the part where I'm having trouble.

INTEGRATE SALESFORCE ACCOUNTS WITH OPPORTUNITIES

One of the more popular “integrations” between Milestones PM+ and Salesforce is linking Projects to Opportunities.

Presently, to set this up, you will need access to a developer to write an easy trigger that will call our global method for automatically creating projects. The trigger should look like this:

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' }); } } } }

Here's the detailed explanation of the bolded fields:
In the CreateChildProject method, there are multiple parameters.

The 'projectCreationField'  parameter is a MANDATORY text field representing the API name for the field containing the value that represents which project template document to search for. It also is the field that when set triggers project creation. Important: You will want to make sure that when creating project templates that you have your template named (document named) according to the value specified by this field. For example, if the value in the API field name referenced by the projectCreationField parameter is "Standard", you will need to make sure that you have a project template named, "Standard" or containing the word "Standard".

The 'projectLookupField1' parameter is a MANDATORY text field representing the API name for the primary lookup on the project object that will connect to your newly created object to the parent object on which the project was automatically created.

The 'projectLookupField2' parameter is an OPTIONAL text field representing the API name for a second lookup on the project object that will connect to your newly created object to an additional parent object.

The 'secondaryLookup' parameter is an OPTIONAL text field representing the API name for an additional lookup fields on the parent object on which the project automatically created. For example, Opportunities have accounts as their parent and if you are creating a project from an opportunity, you can set the Opportunity.'AccountID' field in this field to relate the project to both the opportunity it's account.

The 'Project_Naming_Convention__c' parameter is a MANDATORY text field representing the API name containing the field or formula field that sets the name of your newly created project.

I have heard that PB could be used in lieu of a trigger, which I would be happy to do, but I'm not clear on how to set that up, either. 
Thanks for the help!
Jason CorumJason Corum
I'm currently working on an implementation myself. From what I've seen thus far, it looks like the "projCreationUtil" expects to grab these values from fields on the Opportunity object. Here's what my implementation looks like:

 projCreationUtil.CreateChildProject(trigger.oldMap, trigger.newMap, new Map<string, object>{
                            'projectCreationField' => 'Project_Template__c',
                            'projectLookupField1' => 'Opportunity__c',
                            'projectNamingConventionField' => 'Project_Name__c'
});

Does this help? Also, if you have any thoughts on my Milestones PM+ question, it would be much appreciated. You can see it on my profile - it's the only one I've submitted..
Randi ThompsonRandi Thompson
Thanks, Jason! I will try that out and see if it works. There isn't a lot of support out there for Milestones setup and implementation, so I would love to be able to share tips and pitfalls with you. Maybe together we can stumble through the setup! :)   I'm still a trigger n00b but what are your thoughts on this idea, which a developer associate of mine suggested: use Process Builder for triggers instead of Apex....