• Scott Bub 7
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello Everyone,

I have found bits of code here and there and manipulated to be what I needed. It seems to work for all of the scenarios that I have tried, but I wanted to know if the way that I have written it is inefficient or not as efficient as it could be. Would anyone care to take a look at this code and tell me if they approve or if I should have done something different?

We have two picklist fields with many values on the object. We need the first field to filter down to just certain values in a visualforce page in a managed package, but you can't do that without a dependency. So, we created a second field with all of the same values to allow us to display the second one on the visualforce page with the filtered list based on the one that is selected in the original field. We didn't want to create multiple WFRs for each value so we needed to create a trigger. The trigger should only update the original field when a change has been to the secondary field.

Here is the code for the trigger:

trigger updateOrderStatusWorkOrder on SVMXC_Service_Order__c (before insert, before update) {  
    Map<String, String> myPickListMap = new Map<String, String> {
        'Open'=>'Open', 'In Progress'=>'In Progress', 'Completed'=>'Completed', 'Closed'=>'Closed', 'Cancelled'=>'Cancelled'
    };
    
    for (SVMXC_Service_Order__c wo : Trigger.new)  {
      if(trigger.isUpdate) {
        if(wo.Order_Status__c != trigger.oldMap.get(wo.Id).Order_Status__c &&
            wo.SVMXC_Order_Status__c != wo.Order_Status__c &&
            wo.Order_Status__c != NULL) {
                wo.SVMXC_Order_Status__c = myPickListMap.get(wo.Order_Status__c);        
        }
      }
      if(!trigger.isUpdate) {
          if(wo.SVMXC_Order_Status__c != wo.Order_Status__c &&
              wo.Order_Status__c != NULL){
                wo.SVMXC_Order_Status__c = myPickListMap.get(wo.Order_Status__c);  
          }
      }
    }     
}
I am trying to come up with an expiration date for a custom object's records. The only current fields I can use are the 'created date' of the record and there is a picklist with string values of: 'One Week', 'One Month', 'Three Months', ..... 

I was doing a new custom field on the object called 'Expiration Date' and using the type as date/time formula. Under advanced tab here, I was attempting 'if' statements to assign numbers to each picklist value but got stumped as to the logic and formatting of how this would look.

Can anyone guide me in the correct direction to work on this?

Thank you in advance!