• Kevin DiLoreto
  • NEWBIE
  • 30 Points
  • Member since 2015
  • Salesforce Developer - Lead
  • Renovate America

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
We have encountered an issue with some cases coming in through email-to-case that bouce back becasue the string is too long and exceeds the 32,000 character limit. Support says this is hard coded and cannot increase the limit. The issue is the header that Microsoft is appending to the emails as pushing it over the limit and IT has spoken with them and this also cannot be adjusted. The recommendation from support is to write a trigger to truncate the email header. Since I am not a developer I don't know how to write this trigger. Curious if anyone else has done something like this already. I have looked through the community and can't find much info on this. Any guidance would be much appreciated!
We have encountered an issue with some cases coming in through email-to-case that bouce back becasue the string is too long and exceeds the 32,000 character limit. Support says this is hard coded and cannot increase the limit. The issue is the header that Microsoft is appending to the emails as pushing it over the limit and IT has spoken with them and this also cannot be adjusted. The recommendation from support is to write a trigger to truncate the email header. Since I am not a developer I don't know how to write this trigger. Curious if anyone else has done something like this already. I have looked through the community and can't find much info on this. Any guidance would be much appreciated!
whenever an Account is created or updated Account Team Member Role should be assigned to the team member  based on multiple territory id's... please anyone help me out!!!!  how to do this......

Below is the Apex class and trigger for the Account is created   or updated Account Team Member Role should be assigned to the team member  based on single  territory id...

Apex Class:

public class AccountTeamMember_Class{
    public static void accountTeamAssignInsert(List<Account> newList){
        List<AccountTeamMember> latm = new List<AccountTeamMember>();
        List<AccountShare> las = new List<AccountShare>();
        set<id> setids = new set<id>();
        set<id> accids = new set<id>();
        set<string> listEmails = new set<string>();
        Id uid;
             
        for (Account acc : newList) {
            uid = acc.ownerId;
            for(IDEXX_Water_Territories__c s : IDEXX_Water_Territories__c.getAll().values()){
                 if(acc.Territory_ID__c == s.Territory_ID__c){ 
                     listEmails.add(s.User_Email_Address__c);
                     system.debug('listemails:::::'+listemails);
                 }
            }
        }
        list<User> usr = [SELECT id,name,email,username,profile.name from user where email in : listEmails AND isActive = true];  
        system.debug('user:::::'+usr);
            for(Account acc : newList){
                for(IDEXX_Water_Territories__c s : IDEXX_Water_Territories__c.getAll().values()){
                    for(User u : usr){
                        if(u.email == s.User_Email_Address__c ){
                            system.debug('Acc.ownerId:::'+Acc.ownerId);
                            AccountTeamMember atm = new AccountTeamMember();
                            AccountShare  nas = new AccountShare();
                            atm.AccountId = acc.id;                
                            atm.TeamMemberRole = s.TeamMemberRole__c;
                            atm.UserId= u.id; 
                            latm.add(atm);
                            
                           if(u.profile.name != 'System Administrator' && u.id != acc.ownerid){
                             
                                nas.AccountId =acc.id; 
                                nas.UserOrGroupId =u.id;
                                nas.AccountAccessLevel ='Edit';
                                nas.OpportunityAccessLevel = 'Edit';
                                nas.CaseAccessLevel = 'Edit';
                                las.add(nas);
            
                            }
                         }   
                               
                    }    
                }
            }
            
            try{
            
                
                insert(latm);
                insert(las);
            }catch(DMLException e){
        
                    system.debug('error on insert team members ' + e.getMessage());
            }  
            
    }
    //=============================================UPDATE====================================================================
    public static void accountTeamAssignUpdate(List<Account> newList,List<Account> oldList){
        List<AccountTeamMember> latm = new List<AccountTeamMember>();
        List<AccountShare> las = new List<AccountShare>();
        set<id> setids = new set<id>();
        set<id> accids = new set<id>();
        set<string> listEmails = new set<string>();
        Id uid;
        String oldterritory_id;
        String newterritory_id;
        for(Account a : oldList){
            oldterritory_id = a.Territory_ID__c;
        }
        for(Account a : newList){
            newterritory_id = a.Territory_ID__c;
        }
        if(oldterritory_id != newterritory_id){
            for (Account acc : newList) {
                setids.add(acc.id);
            }
            
            List<AccountTeamMember> oldatm = [select id from AccountTeamMember where AccountId in : setids];
            if(oldatm != null){
                delete(oldatm);
            }
        }
        for (Account acc : newList) {
            uid = acc.ownerId;
            for(IDEXX_Water_Territories__c s : IDEXX_Water_Territories__c.getAll().values()){
                 if(acc.Territory_ID__c == s.Territory_ID__c){ 
                     listEmails.add(s.User_Email_Address__c);
                     system.debug('listemails:::::'+listemails);
                 }
            }
        }
        list<User> usr = [SELECT id,name,email,username,profile.name from user where email in : listEmails AND isActive = true];  
        system.debug('user:::::'+usr);
            for(Account acc : newList){
                for(IDEXX_Water_Territories__c s : IDEXX_Water_Territories__c.getAll().values()){
                    for(User u : usr){
                        if(u.email == s.User_Email_Address__c ){
                            system.debug('Acc.ownerId:::'+Acc.ownerId);
                            AccountTeamMember atm = new AccountTeamMember();
                            AccountShare  nas = new AccountShare();
                            atm.AccountId = acc.id;                
                            atm.TeamMemberRole = s.TeamMemberRole__c;
                            atm.UserId= u.id; 
                            latm.add(atm);
                            
                           if(u.profile.name != 'System Administrator' && u.id != acc.ownerid){
                             
                                nas.AccountId =acc.id; 
                                nas.UserOrGroupId =u.id;
                                nas.AccountAccessLevel ='Edit';
                                nas.OpportunityAccessLevel = 'Edit';
                                nas.CaseAccessLevel = 'Edit';
                                las.add(nas);
            
                            }
                        }    
                               
                    }    
                }
            }
            
            try{
                
                insert(latm); 
                system.debug('latm=========='+latm);
                insert(las);    
                system.debug('las=========='+las);                 
            }catch(DMLException e){
                    system.debug('error on insert team members ' + e.getMessage());
            }  
            
    }
}

Apex Trigger:

trigger AddAccountTeamMember on Account (after insert,after update) {
      if(Trigger.isInsert){
        AccountTeamMember_Class.accountTeamAssignInsert(trigger.new);
    }
    if(Trigger.isUpdate){
        AccountTeamMember_Class.accountTeamAssignUpdate(trigger.new,trigger.old);
    }
}