• Jason Corum
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Junior Web Developer
  • Sol Systems


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hello! I'm working on an Apex Class that gets called from a Trigger to update some related custom objects. I want different behavior based on whether an Integer variable is zero, positive or negative, however it seems like the variable is processed as positive even if it is negative. I've attempted to slim down what I have code-wise for the forum, so there may be some typos in what I include here, but this should give folks the gist. I'd appreciate some more eyes on this to see what I'm missing.
 
public class PopulateCustomObjects {

  public static void addDates(Set<Id> parentId){

      List<CustomObjects__c> customObjectsToUpdate = new List<CustomObjects__c>();

      // Get a List of CustomObjects Associated with the Parent

      for (List<CustomObjects__c> objects : [SELECT Id, Due_Date__c, Start_Date__c, Parent__r.Close_Date__c
                                              FROM CustomObjects__c
                                              WHERE CustomObjects__c_Lookup__c IN :parentId]){

        for(CustomObject__c object : objects){

        // Re-populate the Start Date and Due Date based on the days integer variable

          Integer days = object.Start_Date__c.daysBetween(object.Due_Date__c);

          if(days == 0) {

            object.Start_Date__c = date.today();
            object.Due_Date__c = object.Parent__r.Close_Date__c;

            customObjectsToUpdate.add(object);

          } else if(days > 0) {

            object.Start_Date__c = date.today();
            object.Due_Date__c = BusinessDaysClass.AddBusinessDays(date.today(), days);

            customObjectsToUpdate.add(object);
          } else {

            object.Start_Date__c = BusinessDaysClass.AddBusinessDays(object.Parent__r.Close_Date__c, days);
            object.Due_Date__c = object.Parent__r.Close_Date__c;

            customObjectsToUpdate.add(object);
          }
        }
      update customObjectsToUpdate;
    }
  }
}



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

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

 
Hello! I'm working on an Apex Class that gets called from a Trigger to update some related custom objects. I want different behavior based on whether an Integer variable is zero, positive or negative, however it seems like the variable is processed as positive even if it is negative. I've attempted to slim down what I have code-wise for the forum, so there may be some typos in what I include here, but this should give folks the gist. I'd appreciate some more eyes on this to see what I'm missing.
 
public class PopulateCustomObjects {

  public static void addDates(Set<Id> parentId){

      List<CustomObjects__c> customObjectsToUpdate = new List<CustomObjects__c>();

      // Get a List of CustomObjects Associated with the Parent

      for (List<CustomObjects__c> objects : [SELECT Id, Due_Date__c, Start_Date__c, Parent__r.Close_Date__c
                                              FROM CustomObjects__c
                                              WHERE CustomObjects__c_Lookup__c IN :parentId]){

        for(CustomObject__c object : objects){

        // Re-populate the Start Date and Due Date based on the days integer variable

          Integer days = object.Start_Date__c.daysBetween(object.Due_Date__c);

          if(days == 0) {

            object.Start_Date__c = date.today();
            object.Due_Date__c = object.Parent__r.Close_Date__c;

            customObjectsToUpdate.add(object);

          } else if(days > 0) {

            object.Start_Date__c = date.today();
            object.Due_Date__c = BusinessDaysClass.AddBusinessDays(date.today(), days);

            customObjectsToUpdate.add(object);
          } else {

            object.Start_Date__c = BusinessDaysClass.AddBusinessDays(object.Parent__r.Close_Date__c, days);
            object.Due_Date__c = object.Parent__r.Close_Date__c;

            customObjectsToUpdate.add(object);
          }
        }
      update customObjectsToUpdate;
    }
  }
}



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

 
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!