• Jaci Banton
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi there!

Just starting to learn and trying to figure out how to update a pick list field using a trigger, based on a related list.
If an Account does not have a record in the related list whose date field is within the past year, I want to set the pick list field to 'Inactive'.

1. If you have advice towards when to trigger this, please let me know your thoughts.
2. I am trying to sort the SOQL list and then set the pick list field based on the last date in the list, but can't seem to get it. Do you know of a better way to go about this or how to make this work? Thank You in advance!
trigger IsActive on Account (before update, before insert) { 

    if(Trigger.isAfter || Trigger.isUpdate){

        List<Integer> dates1 = new list<Integer>();{
        for(Account ac : [SELECT Id,Name,(SELECT Event_End_Date__c FROM Experiences_Associated_With_Delivery__r Order By Event_End_Date__c desc) FROM Account Where id IN :Trigger.new]){

            if(dates1.get(dates1.size()-1) > 1) {
            Account.Activity_Status__c = Inactive; 
            } else { Account.Activity_Status_c = Active;
          }
        }
    }
}
}

 
Hi there!

Just starting to learn and trying to figure out how to update a pick list field using a trigger, based on a related list.
If an Account does not have a record in the related list whose date field is within the past year, I want to set the pick list field to 'Inactive'.

1. If you have advice towards when to trigger this, please let me know your thoughts.
2. I am trying to sort the SOQL list and then set the pick list field based on the last date in the list, but can't seem to get it. Do you know of a better way to go about this or how to make this work? Thank You in advance!
trigger IsActive on Account (before update, before insert) { 

    if(Trigger.isAfter || Trigger.isUpdate){

        List<Integer> dates1 = new list<Integer>();{
        for(Account ac : [SELECT Id,Name,(SELECT Event_End_Date__c FROM Experiences_Associated_With_Delivery__r Order By Event_End_Date__c desc) FROM Account Where id IN :Trigger.new]){

            if(dates1.get(dates1.size()-1) > 1) {
            Account.Activity_Status__c = Inactive; 
            } else { Account.Activity_Status_c = Active;
          }
        }
    }
}
}