• Richard Valencia
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
ery new to Triggers and hoping this is a simple replacement of text in the code we already have working in the Account object that was built when we had a Dev support.

What I'm trying to do is make my trigger that I already have work the same way but for cases. When we build Cases we relate it to the account via a lookup and that then brings in the Account Manager, what we need to happen is that whenever the account manager creates either a New task, New Event, Log a call, Mail Merge, or Send an Email it updates the "Last Activity Date" field in the Account object. Here's the Triggers I have for tasks and events:

public class TaskTriggerHandler {
    public static void updateAccountLastActivityDate(){
        List<Task> tskList = (Task[])Trigger.New;
    Set<Id> tskIds = new Set<Id>();
    List<Account> accountsToUpdate = new List<Account>();
    for(Task tsk : tskList){
        system.debug('Account id '+tsk.AccountId);
            tskIds.add(tsk.AccountId);
    }
    List<Account> accList= [Select id,Account_Manager__c,Last_Activity_Date__c,Account_Status__c  from Account where id IN :tskIds];
        system.debug('accList: '+accList);
    if(accList.size() > 0){
        for(Account acc : accList){
            if(acc.Account_Manager__c == UserInfo.getUserId() && acc.Account_Status__c == 'Active' || Test.isRunningTest()){
               acc.Last_Activity_Date__c = Date.today();
              accountsToUpdate.add(acc);   
            }
        }    
    }
    if(accountsToUpdate.size() > 0){
        update accountsToUpdate;
    }
    }
}

public class EventTriggerHandler {
    public static void updateAccountLastActivityDate(){
    List<Event> evtList = (Event[])Trigger.New;
    Set<Id> evtIds = new Set<Id>();
    List<Account> accountsToUpdate = new List<Account>();
    for(Event evt : evtList){
        
        evtIds.add(evt.AccountId);
    }
    List<Account> accList= [Select id,Account_Manager__c,Last_Activity_Date__c,Account_Status__c  from Account where id IN :evtIds];
    if(accList.size() > 0){
        for(Account acc : accList){
            if(acc.Account_Manager__c == UserInfo.getUserId() && acc.Account_Status__c == 'Active' || Test.isRunningTest()){
                acc.Last_Activity_Date__c = Date.today();
                accountsToUpdate.add(acc);
            }
        }    
    }
    if(accountsToUpdate.size() > 0){
        update accountsToUpdate;
    }
    }
}

As a user when trying to upload an attachment in any object i need to be remind of a document that should NOT be inculded. 

example: 

While in an account, when I select add attach file, i would like a reminder that states "Please remove any documents with customer credit card numbers"  

ery new to Triggers and hoping this is a simple replacement of text in the code we already have working in the Account object that was built when we had a Dev support.

What I'm trying to do is make my trigger that I already have work the same way but for cases. When we build Cases we relate it to the account via a lookup and that then brings in the Account Manager, what we need to happen is that whenever the account manager creates either a New task, New Event, Log a call, Mail Merge, or Send an Email it updates the "Last Activity Date" field in the Account object. Here's the Triggers I have for tasks and events:

public class TaskTriggerHandler {
    public static void updateAccountLastActivityDate(){
        List<Task> tskList = (Task[])Trigger.New;
    Set<Id> tskIds = new Set<Id>();
    List<Account> accountsToUpdate = new List<Account>();
    for(Task tsk : tskList){
        system.debug('Account id '+tsk.AccountId);
            tskIds.add(tsk.AccountId);
    }
    List<Account> accList= [Select id,Account_Manager__c,Last_Activity_Date__c,Account_Status__c  from Account where id IN :tskIds];
        system.debug('accList: '+accList);
    if(accList.size() > 0){
        for(Account acc : accList){
            if(acc.Account_Manager__c == UserInfo.getUserId() && acc.Account_Status__c == 'Active' || Test.isRunningTest()){
               acc.Last_Activity_Date__c = Date.today();
              accountsToUpdate.add(acc);   
            }
        }    
    }
    if(accountsToUpdate.size() > 0){
        update accountsToUpdate;
    }
    }
}

public class EventTriggerHandler {
    public static void updateAccountLastActivityDate(){
    List<Event> evtList = (Event[])Trigger.New;
    Set<Id> evtIds = new Set<Id>();
    List<Account> accountsToUpdate = new List<Account>();
    for(Event evt : evtList){
        
        evtIds.add(evt.AccountId);
    }
    List<Account> accList= [Select id,Account_Manager__c,Last_Activity_Date__c,Account_Status__c  from Account where id IN :evtIds];
    if(accList.size() > 0){
        for(Account acc : accList){
            if(acc.Account_Manager__c == UserInfo.getUserId() && acc.Account_Status__c == 'Active' || Test.isRunningTest()){
                acc.Last_Activity_Date__c = Date.today();
                accountsToUpdate.add(acc);
            }
        }    
    }
    if(accountsToUpdate.size() > 0){
        update accountsToUpdate;
    }
    }
}

As a user when trying to upload an attachment in any object i need to be remind of a document that should NOT be inculded. 

example: 

While in an account, when I select add attach file, i would like a reminder that states "Please remove any documents with customer credit card numbers"