• Jim Montgomery
  • NEWBIE
  • 160 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 56
    Replies
I need to conver this triger to a class. get stuck on the after delete part.

trigger CCHIQPromotion on Quote_Promotion__c (after insert, after update, after delete) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    
    If(trigger.Isdelete){
for (Quote_Promotion__c childObj : Trigger.old) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.old){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.CCH_Axcess_IQ_Promotion__c = true;
        }
        else
        {
       myParentProposal.CCH_Axcess_IQ_Promotion__c = false;
       }
    }
    update parentProposal.values();
    }
    
if(Trigger.IsInsert)
{
    for (Quote_Promotion__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
   } 
   if(Trigger.IsUpdate)
{
    for (Quote_Promotion__c childObj : Trigger.new) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,TMA_Q4_Promotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c = 'USZP-BGYY_AXCESSIQ_100') FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.CCH_Axcess_IQ_Promotion__c = true;
        }
        
    
    update parentProposal.values();
    }
   } 
   }
I have 3 triggers like the one in this class I need add into this class. Not sure how to add them in.

public class HasFlagsTriggerHandler {
    
     public static void HasTax(List<Apttus_Proposal__Proposal_line_item__c> props){
        Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    

    for (Apttus_Proposal__Proposal_Line_Item__c childObj : props) {
        listIds.add(childObj.Apttus_Proposal__Proposal__c);
        LineItems.add(childObj.Id);
    }
parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,Has_Tax_Lines__c,(Select Id from R00N70000001yUfBEAU__r where Product_Family__c = 'Tax'LIMIT 1) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Apttus_Proposal__Proposal_Line_Item__c ProposalLineItem: props){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c);
        if(parentProposal.containsKey(ProposalLineItem.Apttus_Proposal__Proposal__c) && parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size() > 0)
        {
            myParentProposal.Has_Tax_Lines__c = true;
        }
        else
        {
            myParentProposal.Has_Tax_Lines__c = false ;
        }
    }
    update parentProposal.values();
    }
 
I have this onclick javascript invoked and in the part that is commented out, need to check for the "send_tax_migration_email__c is not checked..
Tried a bunch of stuff, but nothing is working.

<apex:page standardController="Apttus_Proposal__Proposal__c">
<script src="/soap/ajax/10.0/connection.js"> </script >
<script src="/soap/ajax/10.0/apex.js"> </script >
<script type="text/javascript">
window.onload=init() function init() { var p = new sforce.SObject('Apttus_Proposal__Proposal__c'); p.Id = "{!Apttus_Proposal__Proposal__c.Id}"; if("{!Apttus_Proposal__Proposal__c.Has_SureTax_text__c}" =='True' && ("{!apttus_proposal__proposal__c.SureTax_Overage_Percentage__c}" =='' ||"{!apttus_proposal__proposal__c.SureTax_Overage_Percentage__c}" == null)) { alert("You must enter a SureTax Overage Percentage"); } else
//if("{!apttus_proposal__proposal__c.Has_tax_Migration_Products__c}">0 && "{!apttus_proposal__proposal__c.Send_Tax_Migration_Email__c}" !=='True')
//{
//alert("You must send the Tax Migration email")
//}
//else
{ p.apttus_proposal__approval_stage__c = "Submitted to COP";
p.SAP_Order_Processing_Stage__c = "Submitted to COP";
p.Proposal_Submitted_By__c = sforce.connection.getUserInfo().userId; }
result = sforce.connection.update([p]);
location.href="https://wktaa.my.salesforce.com/"+p.Id; };
</script>
</apex:page>
I need to get the MAX value of the extended_maintenance_months__c field on the R00N70000001yUfBEAU__r relationship (proposal_line_item__c), then flag that on the proposal.

trigger HasExtendedMaintenance on Apttus_Proposal__Proposal_Line_Item__c (after insert,after update) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();

    for (Apttus_Proposal__Proposal_Line_Item__c childObj : Trigger.new) {
        listIds.add(childObj.Apttus_Proposal__Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,Extended_Maintenance_months__c,(Select id,extended_maintenance_months__c from R00N70000001yUfBEAU__r where Extended_Maintenance_Months__c > 0 ) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Apttus_Proposal__Proposal_Line_Item__c ProposalLineItem: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c);
        if(parentProposal.containsKey(ProposalLineItem.Apttus_Proposal__Proposal__c) && parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size() > 0)
        {
            myParentProposal.extended_maintenance_months__c = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size();
            myParentProposal.extended_maintenance__c = True;         
        }    
       else
       {
       myParentProposal.extended_maintenance_months__c =0;
       myParentProposal.request_extended_maintenance_approval__c = false;
       myParentProposal.extended_maintenance_Approved__c = false;
       myParentProposal.extended_maintenance__c = False;
       }
       }

               update parentProposal.values();
}
I hav ethis trigger that should update the parent account with the sum of number of documents from the child AC_Trial object. It is not updating the account.

trigger ACTrialRollup on AC_Trial__c (after insert, after update, after delete) {

    
    List<Account> list_Account= new List<Account>();
    set<Id> set_ACTrial = new set<Id>();
    for(AC_Trial__c objACT: trigger.new){
        set_ACTrial.add(objACT.Account__c);
    }
    Decimal Sum;
    for(Account objAccount : [SELECT Id,Name,(SELECT Id,Name,Number_Of_Documents__c FROM AC_Trial__r) FROM Account WHERE Id IN: set_ACTrial]){
        Sum=0;
        for(AC_Trial__c objACT01: objAccount.AC_Trial__r ){
            Sum+=objACT01.Number_Of_Documents__c ;
        }
        objAccount.AC_Trial_Documents__c=Sum;
        list_Account.add(objAccount);
    }
    update list_Account;
}
I have a custom object names Project. When I log a call as a task, the related to is the project Id. I assume that is the WhatId field on the task object. I need to be able to also have this task show up on the accounts activity history related list as well. I have a trigger, but get the error "Field is no writeable Task.AccountId."
Here is my code.
Not quite sure how to use a for loop in this.
public class AccExtensions{
      transient Public List<Account> AHS{get;set;}
             
                 public AccExtensions(ApexPages.StandardController controller) {
          AHS=[select id,(select id,ActivityDate,short_notes__c,OwnerId, Owner.name,Activity_Type__c,description,subject,Who.Id,Who.Name from ActivityHistories where (owner.id<>'005i0000001gIQJAA2' and owner.id<>'00531000008bhlRAAQ') order by activitydate DESC ) from account where ID=:ApexPages.currentPage().getParameters().get('id') ];
                     
          System.Debug('AHS: ' + AHS.get(0));
        System.Debug('Activities: ' + AHS.get(0).ActivityHistories);
        
}

}
Here is my trigger code. Should count the number of events associated to the account the contact belongs to.
It is not updating the account.

trigger SoftwareOwnerEventRollupContact on Event (after insert, after update, after delete) {
    
    if(Trigger.isAfter && Trigger.isInsert){
    Event T = [select Id,subject, WhoId from event where Id = :trigger.new[0].Id];   
    if(trigger.new[0].Id!=null){
    if(T.whoID!=null){
    String WhoId = t.WhoId;
    
    if(Whoid.startswith('003')){
    
       Contact C = [select id, accountid from contact where id = :WhoId];
        
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =:C.AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        update a;
        
        
        }
        }
        
  }
  }
  }
}
Here is my code. Will work on insert, but not on befroe update.
trigger SoftwareOwnerEventRollup on Event (after insert, before update, after delete) {
   
    
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isDelete)){
    Event T = [select Id,subject, WhatId from event where Id = :trigger.new[0].Id];   
    if(trigger.new[0].Id!=null){
    if(T.whatID!=null){
    String WhatId = t.WhatId;
    
    if(Whatid.startswith('001')  || Whatid.startswith('006')){
    
        
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =: trigger.new[0].AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId =: trigger.new[0].AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        update a;
        
        
        }
        }
        
  }
  }
  }
  
  if (trigger.isBefore && trigger.isUpdate){
  
      For(Event T : trigger.new){
      if(T.WhatID!=null){
    
    String WhatId = t.WhatId;
    
    if(Whatid.startswith('001') || Whatid.startswith('006')){      
     
    
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =: trigger.new[0].AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId =: trigger.new[0].AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        
        
        
        }
        }
        
  
  }
   }
   }
   }
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product> listprd = [SELECT Id, productcode, productname,productfamily,erp__c
        FROM product where isactive = true];
        if(listprd.size() > 0) {
            for(product prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public Product prd {get;set;}
        public WrapperClass(product prd) {
            this.prd = prd;
        }
    }
    
     public PageReference save()
    {
    PageReference caserec = new PageReference('/'+caseID);
    caserec.setredirect(true);
    return caserec;
    }
    
    public void add() {
        List<product> listprdforAdd = new List<product>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listprdforAdd.add(w.prd);
            } 
        }
        //insert listWrapper into case_cancelled_inventory__c
        List<case_added_inventory__c> listCaseAddedInventory = new List<case_Added_inventory__c>();
   for(aproduct objprd : listprdforAdd){
    case_added_inventory__c objCaseAddedInventory = new case_added_inventory__c();     
    objCaseAddedInventory.Product_Code__c = objprd.productcode;
    objCaseAddedInventory.Product_Name__c = objprd.productname;
        objCaseAddedInventory.case__c = caseID;
    listCaseAddedInventory.add(objCaseAddedInventory);   
   }
   if(listCaseAddedInventory != null && listCaseAddedInventory.size() > 0)
    insert listAddedCaseInventory;
  //insert listWrapper into case_cancelled_inventory__c Ends

 
    }
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
Too many soql errors trigger msa data line 73

Getting error on this trigger fro one test class, but works fine from another test class.
trigger MSAData on Account (before insert,before update) {  
               Trigger

Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();   
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }    
    for(Account A:Trigger.new) {    
        AZipCode.add(A.billingpostalcode);
    }    
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
if(trigger.isUpdate){    
    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
        AZipCode.add(acct.billingpostalcode);
        } 
    }
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }  
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
            AZipCode.add(A.billingpostalcode);  
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}

Test Class
@isTest 
private class TestTaskEventRollup_RecordType {

    static testMethod void InsertTask() {

Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            recordtypeid = '012i0000000Ou0CAAS',
            software_owner__C = '005i0000001gISQAA2' );
        insert A;
       

Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
 Contact c = new Contact(
        firstname = 'Jim', lastname = 'Montgomery');
        Insert c;

 Opportunity O = new Opportunity(
        Name = 'TestOpp',
        accountId = A.Id,
        type = 'New to Existing',
        Closedate = Date.today().addYears(1),
        stagename = '1. Gain Access',
        product_category__c = 'Med/Large Software',
        Amount = 1.00,
        product_Sub_Category__c = 'Tax');
        insert O;
        
       Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
insert tsk;

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk2;

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk3;
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt;

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt1;

Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt2;
}
}
Works on update, but not o insert

Works fine on update, but not on insert. Record Type is not stamped on the activity.


trigger TaskAccountTypeContact on Task (before insert, before update) {
   For (Task T : trigger.new){            
            string WhoID = t.WhoID;
    if(t.WhoId!=NULL){
   if(WhoID.startswith('0')){
   if(T.AccountID!=NULL){
    Account a = [select id,recordtypeid from Account where id =:T.AccountId]; 
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account';                
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';                
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';               
        }
}
}
}
}
}
I have a trigger on task that will update the task with the accounts record type on insertion.
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.

trigger TaskAccountType on Task (after insert) {
    Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
    if(trigger.new[0].Id!=null){
    string WhatId = t.WhatId;
    
    if(t.WhatId!=NULL){
   if(WhatId.startswith('0')){
    Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){  
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account'; 
        update T;       
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';  
        update T;      
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';  
        update T;      
        }
}
}
}
}
}
I am trying to add a field from the account when creating a task on an opportunity or account, or contact. I should be able to access the AccountId field on the task record to pull this,.

trigger AccountRecordType on Task (before insert, before update) {
for (Task T : trigger.New){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];    
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c = 'Customer Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account Account';        
        }
}
}
Cannot find out why on a delete the checkbox is not being updated to false.

trigger HasSFTRPromotion on Quote_Promotion__c (after insert, after update, before delete) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    
    If(trigger.Isdelete){
for (Quote_Promotion__c childObj : Trigger.old) {
        listIds.add(childObj.Quote_Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,HasSFTRPromotion__c,(Select id from Promotion_Groups__r where Promotion_Code__c IN('26645', '26646', '26647', '26648', '26649', '26650', '26651', '26652', '26653', '26654', '26655', '26656'
)) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Quote_Promotion__c QPromo: Trigger.old){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(QPromo.Quote_Proposal__c);
        if(parentProposal.containsKey(QPromo.Quote_Proposal__c) && parentProposal.get(QPromo.Quote_Proposal__c).Promotion_Groups__r.size() > 0)
        {
            myParentProposal.HasSFTRPromotion__c = true;
        }
        else
        {
       myParentProposal.HasSFTRPromotion__c = false;
       }
    }
    update parentProposal.values();
    }
Here is my trigger and test class. I can create an account with the exact same properties as they account in the test class, and it works fine. But thr test class fails with this error.
Error:
System.DmlException: Update failed. First exception on row 0 with id 0010x00000FTfC0AAL; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RCLeadAutoCreateFromAccount: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3010x0000000W9o. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

Trigger.RCLeadAutoCreateFromAccount: line 24, column 1: []
Stack TraceClass.TestRCLeadAutoCreate.insertAccount: line 27, column 1


Trigger:
trigger RCLeadAutoCreateFromAccount on Account (after update) {
    for (Account A:Trigger.New){
    String Name = UserInfo.getName();
         Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.RC_Lead_TimeStamp__c != A.RC_Lead_TimeStamp__c){
        Campaign C = [select id from campaign where name = '18--support-phone inbound-torrance'];
              Lead L = new Lead(
                company = A.name,
                status = 'Not Started',
                lastname = 'RC Lead',
                rating = 'Hot',
                market_segment__c = A.Market_Segment__c,
                market_sub_segment__c = A.Market_Sub_Segment__c,
                street = a.billingstreet,
                city = a.billingcity,
                state = a.billingstate,
                PostalCode = a.BillingPostalCode,
                named_account_type__c = a.Named_Account_Type__c,
                related_account__c = a.Id,
                description = a.rc_lead_comments__c,
                rc_lead_product_interest__c = a.rc_lead_product_interest_MS__c);
            insert L;
            if(A.Named_Account_Type__c == 'Small Firm Tax Customer'){
                L.small_market_N2E__c = True;
                update L;
            }
            campaignmember CM = new campaignmember(
                campaignID = C.Id, 
                comments__c = a.rc_lead_comments__c,             
                leadID = L.ID
                    );
                insert cm;
                             
        }
        
    
    }
}

Test Class:
@isTest 
private class TestRCLeadAutoCreate {

    static testMethod void insertAccount() {
    string name = 'Jim Montgomery';
   Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            market_segment__c = 'Accounting Firms',
            market_sub_segment__c = 'Sole Proprietor',
            billingstate = 'CA',
            named_account_type__c = 'Strategic',
            rc_lead_comments__c = 'Test',
            rc_lead_product_interest_ms__c = 'Pfx Tax'
            );
        insert A;
        Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
        a.rc_lead_timestamp__c = system.now();
        update a;
        }
        }
Not sure where this is erroring out.

trigger MSAData on Account (before insert,before update) { 
    for (account Acc:trigger.new){       
               
Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();  
  
        
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
    
    for(Account A:Trigger.new) {    
    AZipCode.add(A.billingpostalcode);
        
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
else                    

    
if(trigger.isUpdate){    

    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
    
    for(Account A:Trigger.new) {
        
       
           
    AZipCode.add(A.billingpostalcode);
       
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
    }
    
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
        
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}
}
}
}
I am getting error Invalid Type: listAIRforAdd line 39
Code:
public class CaseInventory {

    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    
    public CaseInventory() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    String caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<ams_inventory_rollup__c> listAIR = [SELECT Id, Name, product_name__c,quantity__c,pfx_account_number__c 
        FROM ams_inventory_rollup__c where AccountId__c = :accountId];
        if(listAIR.size() > 0) {
            for(ams_inventory_rollup__c air : listAIR) {
                listWrapper.add(new WrapperClass(air));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public ams_inventory_rollup__c air {get;set;}
        public WrapperClass(ams_inventory_rollup__c air) {
            this.air = air;
        }
    }
    
    public void add() {
        List<ams_inventory_rollup__c> listAIRforAdd = new List<ams_inventory_rollup__c>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listAIRforAdd.add(w.air);
            } 
        }
        
    }
  List<Case_Inventories__c> CaseINVs = new List<case_Inventories__c>();
    
    for(listAIRforAdd wrAIR:listWrapper){
    case_inventories__c CI = new case_inventories__c();
    ci.product_code__c = wrAIR.name;
    ci.product_name__c = wrAIR.product_name__c;
    ci.quantity__c = wrAIR.quantity;
    CaseINVs.add(wrAIR);
    }
    Insert CaseINVs;
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
 
I have this controller<

public class AIRList {   
    public ApexPages.StandardSetController setAIR {
            get {
            if(setAIR == null) {
String accountID = System.currentPageReference().getParameters().get('accountID');
String caseID = System.currentPagereference().getParameters().get('caseID');
                setAIR = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT id,Name, product_name__c,quantity__c,pfx_account_number__c FROM ams_inventory_rollup__c where accountID__c = :accountId]));

            }
            return setAIR;
        }
        set;
    }
        public List<AMS_Inventory_Rollup__c> getAMSInventories() {
        return (List<AMS_Inventory_Rollup__c>) setAIR.getRecords();
    }
}
That populates this VF page, 

<apex:page controller="AIRList"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!AMSInventories}" var="a"> <apex:column > <apex:inputCheckbox /> </apex:column> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Product_Name__c}"/> <apex:column value="{!a.Quantity__c}"/> <apex:column value="{!a.PFX_Account_Number__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

I need to take the selected items form the page, and add them to a case related object/List. Case_cancelled_Inventories that is the child in a masetr/detail relationship to case.
Invalid bind expression type of Case for column of type Id line 9

public class CaseAMSInventory {
Public Case CaseAcct{get;set;}
    

      transient Public List<AMS_Inventory_Rollup__c> CI{get;set;}
             
                 public CaseAMSInventory(ApexPages.StandardController controller) {
                     CaseAcct=[select AccountID from case where ID = :ApexPages.currentPage().getParameters().get('id') ];
          CI=[select id,(select id,name,product_name__c,quantity__c, PFX_Account_Number__c from AMS_Inventory_Rollups__r where accountID__c =:CaseAcct ) from Case where ID=:ApexPages.currentPage().getParameters().get('id') ];
                     
         // System.Debug('CI: ' + CI.get(0));
        //System.Debug('Inventory: ' + CI.get(0).AMS_Inventory_rollups);
        
}

}


 
I have 3 triggers like the one in this class I need add into this class. Not sure how to add them in.

public class HasFlagsTriggerHandler {
    
     public static void HasTax(List<Apttus_Proposal__Proposal_line_item__c> props){
        Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();
    

    for (Apttus_Proposal__Proposal_Line_Item__c childObj : props) {
        listIds.add(childObj.Apttus_Proposal__Proposal__c);
        LineItems.add(childObj.Id);
    }
parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,Has_Tax_Lines__c,(Select Id from R00N70000001yUfBEAU__r where Product_Family__c = 'Tax'LIMIT 1) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Apttus_Proposal__Proposal_Line_Item__c ProposalLineItem: props){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c);
        if(parentProposal.containsKey(ProposalLineItem.Apttus_Proposal__Proposal__c) && parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size() > 0)
        {
            myParentProposal.Has_Tax_Lines__c = true;
        }
        else
        {
            myParentProposal.Has_Tax_Lines__c = false ;
        }
    }
    update parentProposal.values();
    }
 
I need to get the MAX value of the extended_maintenance_months__c field on the R00N70000001yUfBEAU__r relationship (proposal_line_item__c), then flag that on the proposal.

trigger HasExtendedMaintenance on Apttus_Proposal__Proposal_Line_Item__c (after insert,after update) {
Map<ID, Apttus_Proposal__Proposal__c> parentProposal = new Map<ID, Apttus_Proposal__Proposal__c>();
    
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();

    for (Apttus_Proposal__Proposal_Line_Item__c childObj : Trigger.new) {
        listIds.add(childObj.Apttus_Proposal__Proposal__c);
        LineItems.add(childObj.Id);
    }
  
    parentProposal = new Map<Id, Apttus_Proposal__Proposal__c>([SELECT id,Extended_Maintenance_months__c,(Select id,extended_maintenance_months__c from R00N70000001yUfBEAU__r where Extended_Maintenance_Months__c > 0 ) FROM Apttus_Proposal__Proposal__c WHERE ID IN :listIds]);
    
    for (Apttus_Proposal__Proposal_Line_Item__c ProposalLineItem: Trigger.new){
         Apttus_Proposal__Proposal__c myParentProposal = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c);
        if(parentProposal.containsKey(ProposalLineItem.Apttus_Proposal__Proposal__c) && parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size() > 0)
        {
            myParentProposal.extended_maintenance_months__c = parentProposal.get(ProposalLineItem.Apttus_Proposal__Proposal__c).R00N70000001yUfBEAU__r.size();
            myParentProposal.extended_maintenance__c = True;         
        }    
       else
       {
       myParentProposal.extended_maintenance_months__c =0;
       myParentProposal.request_extended_maintenance_approval__c = false;
       myParentProposal.extended_maintenance_Approved__c = false;
       myParentProposal.extended_maintenance__c = False;
       }
       }

               update parentProposal.values();
}
I hav ethis trigger that should update the parent account with the sum of number of documents from the child AC_Trial object. It is not updating the account.

trigger ACTrialRollup on AC_Trial__c (after insert, after update, after delete) {

    
    List<Account> list_Account= new List<Account>();
    set<Id> set_ACTrial = new set<Id>();
    for(AC_Trial__c objACT: trigger.new){
        set_ACTrial.add(objACT.Account__c);
    }
    Decimal Sum;
    for(Account objAccount : [SELECT Id,Name,(SELECT Id,Name,Number_Of_Documents__c FROM AC_Trial__r) FROM Account WHERE Id IN: set_ACTrial]){
        Sum=0;
        for(AC_Trial__c objACT01: objAccount.AC_Trial__r ){
            Sum+=objACT01.Number_Of_Documents__c ;
        }
        objAccount.AC_Trial_Documents__c=Sum;
        list_Account.add(objAccount);
    }
    update list_Account;
}
I have a custom object names Project. When I log a call as a task, the related to is the project Id. I assume that is the WhatId field on the task object. I need to be able to also have this task show up on the accounts activity history related list as well. I have a trigger, but get the error "Field is no writeable Task.AccountId."
Here is my code.
Not quite sure how to use a for loop in this.
public class AccExtensions{
      transient Public List<Account> AHS{get;set;}
             
                 public AccExtensions(ApexPages.StandardController controller) {
          AHS=[select id,(select id,ActivityDate,short_notes__c,OwnerId, Owner.name,Activity_Type__c,description,subject,Who.Id,Who.Name from ActivityHistories where (owner.id<>'005i0000001gIQJAA2' and owner.id<>'00531000008bhlRAAQ') order by activitydate DESC ) from account where ID=:ApexPages.currentPage().getParameters().get('id') ];
                     
          System.Debug('AHS: ' + AHS.get(0));
        System.Debug('Activities: ' + AHS.get(0).ActivityHistories);
        
}

}
Here is my trigger code. Should count the number of events associated to the account the contact belongs to.
It is not updating the account.

trigger SoftwareOwnerEventRollupContact on Event (after insert, after update, after delete) {
    
    if(Trigger.isAfter && Trigger.isInsert){
    Event T = [select Id,subject, WhoId from event where Id = :trigger.new[0].Id];   
    if(trigger.new[0].Id!=null){
    if(T.whoID!=null){
    String WhoId = t.WhoId;
    
    if(Whoid.startswith('003')){
    
       Contact C = [select id, accountid from contact where id = :WhoId];
        
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =:C.AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        update a;
        
        
        }
        }
        
  }
  }
  }
}
Here is my code. Will work on insert, but not on befroe update.
trigger SoftwareOwnerEventRollup on Event (after insert, before update, after delete) {
   
    
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isDelete)){
    Event T = [select Id,subject, WhatId from event where Id = :trigger.new[0].Id];   
    if(trigger.new[0].Id!=null){
    if(T.whatID!=null){
    String WhatId = t.WhatId;
    
    if(Whatid.startswith('001')  || Whatid.startswith('006')){
    
        
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =: trigger.new[0].AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId =: trigger.new[0].AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        update a;
        
        
        }
        }
        
  }
  }
  }
  
  if (trigger.isBefore && trigger.isUpdate){
  
      For(Event T : trigger.new){
      if(T.WhatID!=null){
    
    String WhatId = t.WhatId;
    
    if(Whatid.startswith('001') || Whatid.startswith('006')){      
     
    
        Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =: trigger.new[0].AccountId];
        Id SoftwareOwner = a.software_Owner__c;
        if(softwareOwner != NULL){
        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
    Id LoggedUserId;
       Id CustodialRep = u.custodial_rep__c;
       if(custodialRep!=null){
       LoggedUserId = u.custodial_rep__c;
       }
       else  {
       LoggedUserId = a.software_owner__c;
       }
         
        Integer i = [select count() from Event where AccountId =: trigger.new[0].AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
        
        a.Software_Owner_meeting_demo__c=i;
        
        
        
        }
        }
        
  
  }
   }
   }
   }
public class CaseAddedProducts {
    public List<WrapperClass> listWrapper {get;set;}
    public Boolean allBool {get;set;}
    public  String caseID {get;set;}
    public CaseAddedProducts() {
    String accountID = System.currentPageReference().getParameters().get('accountID');
    caseID = System.currentPagereference().getParameters().get('caseID'); 
        listWrapper = new List<WrapperClass>();
        List<product> listprd = [SELECT Id, productcode, productname,productfamily,erp__c
        FROM product where isactive = true];
        if(listprd.size() > 0) {
            for(product prd : listprd) {
                listWrapper.add(new WrapperClass(prd));
            }
        }
    }
    
    public class WrapperClass {
        public Boolean checked {get;set;}
        public Product prd {get;set;}
        public WrapperClass(product prd) {
            this.prd = prd;
        }
    }
    
     public PageReference save()
    {
    PageReference caserec = new PageReference('/'+caseID);
    caserec.setredirect(true);
    return caserec;
    }
    
    public void add() {
        List<product> listprdforAdd = new List<product>();
        List<WrapperClass> listTempWrapper = new List<WrapperClass>();
        for(WrapperClass w : listWrapper) {
            if(w.checked) {
                listprdforAdd.add(w.prd);
            } 
        }
        //insert listWrapper into case_cancelled_inventory__c
        List<case_added_inventory__c> listCaseAddedInventory = new List<case_Added_inventory__c>();
   for(aproduct objprd : listprdforAdd){
    case_added_inventory__c objCaseAddedInventory = new case_added_inventory__c();     
    objCaseAddedInventory.Product_Code__c = objprd.productcode;
    objCaseAddedInventory.Product_Name__c = objprd.productname;
        objCaseAddedInventory.case__c = caseID;
    listCaseAddedInventory.add(objCaseAddedInventory);   
   }
   if(listCaseAddedInventory != null && listCaseAddedInventory.size() > 0)
    insert listAddedCaseInventory;
  //insert listWrapper into case_cancelled_inventory__c Ends

 
    }
    
    public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }
        }
    }
}
Too many soql errors trigger msa data line 73

Getting error on this trigger fro one test class, but works fine from another test class.
trigger MSAData on Account (before insert,before update) {  
               Trigger

Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();   
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }    
    for(Account A:Trigger.new) {    
        AZipCode.add(A.billingpostalcode);
    }    
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
if(trigger.isUpdate){    
    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
        AZipCode.add(acct.billingpostalcode);
        } 
    }
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }  
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
            AZipCode.add(A.billingpostalcode);  
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}

Test Class
@isTest 
private class TestTaskEventRollup_RecordType {

    static testMethod void InsertTask() {

Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            recordtypeid = '012i0000000Ou0CAAS',
            software_owner__C = '005i0000001gISQAA2' );
        insert A;
       

Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
 Contact c = new Contact(
        firstname = 'Jim', lastname = 'Montgomery');
        Insert c;

 Opportunity O = new Opportunity(
        Name = 'TestOpp',
        accountId = A.Id,
        type = 'New to Existing',
        Closedate = Date.today().addYears(1),
        stagename = '1. Gain Access',
        product_category__c = 'Med/Large Software',
        Amount = 1.00,
        product_Sub_Category__c = 'Tax');
        insert O;
        
       Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
insert tsk;

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk2;

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk3;
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt;

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt1;

Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt2;
}
}
I have a trigger on task that will update the task with the accounts record type on insertion.
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.

trigger TaskAccountType on Task (after insert) {
    Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
    if(trigger.new[0].Id!=null){
    string WhatId = t.WhatId;
    
    if(t.WhatId!=NULL){
   if(WhatId.startswith('0')){
    Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){  
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c ='Customer Account'; 
        update T;       
        }
        else
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';  
        update T;      
        }
        else
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account';  
        update T;      
        }
}
}
}
}
}
Here is my trigger and test class. I can create an account with the exact same properties as they account in the test class, and it works fine. But thr test class fails with this error.
Error:
System.DmlException: Update failed. First exception on row 0 with id 0010x00000FTfC0AAL; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RCLeadAutoCreateFromAccount: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3010x0000000W9o. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

Trigger.RCLeadAutoCreateFromAccount: line 24, column 1: []
Stack TraceClass.TestRCLeadAutoCreate.insertAccount: line 27, column 1


Trigger:
trigger RCLeadAutoCreateFromAccount on Account (after update) {
    for (Account A:Trigger.New){
    String Name = UserInfo.getName();
         Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.RC_Lead_TimeStamp__c != A.RC_Lead_TimeStamp__c){
        Campaign C = [select id from campaign where name = '18--support-phone inbound-torrance'];
              Lead L = new Lead(
                company = A.name,
                status = 'Not Started',
                lastname = 'RC Lead',
                rating = 'Hot',
                market_segment__c = A.Market_Segment__c,
                market_sub_segment__c = A.Market_Sub_Segment__c,
                street = a.billingstreet,
                city = a.billingcity,
                state = a.billingstate,
                PostalCode = a.BillingPostalCode,
                named_account_type__c = a.Named_Account_Type__c,
                related_account__c = a.Id,
                description = a.rc_lead_comments__c,
                rc_lead_product_interest__c = a.rc_lead_product_interest_MS__c);
            insert L;
            if(A.Named_Account_Type__c == 'Small Firm Tax Customer'){
                L.small_market_N2E__c = True;
                update L;
            }
            campaignmember CM = new campaignmember(
                campaignID = C.Id, 
                comments__c = a.rc_lead_comments__c,             
                leadID = L.ID
                    );
                insert cm;
                             
        }
        
    
    }
}

Test Class:
@isTest 
private class TestRCLeadAutoCreate {

    static testMethod void insertAccount() {
    string name = 'Jim Montgomery';
   Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            market_segment__c = 'Accounting Firms',
            market_sub_segment__c = 'Sole Proprietor',
            billingstate = 'CA',
            named_account_type__c = 'Strategic',
            rc_lead_comments__c = 'Test',
            rc_lead_product_interest_ms__c = 'Pfx Tax'
            );
        insert A;
        Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
        a.rc_lead_timestamp__c = system.now();
        update a;
        }
        }
Not sure where this is erroring out.

trigger MSAData on Account (before insert,before update) { 
    for (account Acc:trigger.new){       
               
Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();  
  
        
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
    
    for(Account A:Trigger.new) {    
    AZipCode.add(A.billingpostalcode);
        
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
else                    

    
if(trigger.isUpdate){    

    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
    
    for(Account A:Trigger.new) {
        
       
           
    AZipCode.add(A.billingpostalcode);
       
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
    }
    
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
        
    AZipCode.add(A.billingpostalcode);
  for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {

    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
 }

  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}
}
}
}