• Chuck M Rohllf
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
My code below is functional when updating accounts manually.....however, when I update several accounts with Data Loader I'm getting nothing but timeout errors - this is even with a small batch selected. I'm sure my code could use some clean-up to run more efficiently and avoid the errors.  I'm far from a developer - can anyone assist?  Thank you!
trigger AccountGetTerritoryReference on Account (before insert, before update) {

    Map<String,Territory_Reference__c> Terr2Terr_SA = new Map<String,Territory_Reference__c>();
    Map<String,Territory_Reference__c> Terr2Terr_DTT = new Map<String,Territory_Reference__c>();
  
    Set<String> SA = new Set<String>();
    
    Map<String,Contact> Contact_Estab_Id = new Map<String, Contact>();
    
    Set<String> CID = new Set<String>();
 if(checkRecursive.runOnce())   
    for(Account a:Trigger.new)
    {
        if (a.RecordTypeId == '012E0000000PR3u')
    {
        if (a.Agency__c<>null){
            //something new
            SA.add(a.Agency__c);
            a.Agency_Name__c = a.Agency__c; // the default agency name will be the SA
        }
        
        else if (a.Agency__c==null )
        {
            a.Agency_Name__c = '';  
        }
       
    }
                a.NAIS_VOSS_Mgr__c = null;
                a.NAIS_VSEN_Mgr__c = null;
                a.MSO__c = null;
                a.PSE_Representative__c = null;
                a.PSM__c = null;
                a.RMOS__c = null;
                a.VOSS__c = null;
                a.VPSO__c = null;
                a.MTSS__c = null;
                a.Xerox_Entity__c = null;
                a.Area_Title_t2t__c = null;      
                a.ASD__c = null;
                a.CBM__c = null;
                a.VSPM__c = null;
                a.MPS_Manager__c = null;
    
    
    }
    
    for (Territory_Reference__c t : [SELECT MTSS__c,NAIS_VOSS_Mgr__c,VSEN__c,NAIS_VSEN_Mgr__c,AGENT_DTT__c,AGENCY__c,AGENCY_ID__c,SA_DTT_KEY__c,VOSS__c,PSE__c,PSM__c,MSO__c,RVP__c,Area_Title__c,REGION__c,RMOS__c,ASD__c,CBM__c,VPSE__c,VSPM__c FROM Territory_Reference__c WHERE AGENCY_ID__c IN : SA]){
        Terr2Terr_SA.put(t.AGENCY_ID__c,t);
        Terr2Terr_DTT.put(t.AGENT_DTT__c,t);      
    }
    

    if (!Terr2Terr_SA.isEmpty())
    {
        for(Account a:Trigger.new)
        {

            if (Terr2Terr_DTT.get(a.Dtt__c)<>null){
                Territory_Reference__c  t2t = Terr2Terr_DTT.get(a.Dtt__c);
                a.Agency_Name__c = t2t.AGENCY__c;
                a.Inside_Sales_Representive__c = t2t.VSEN__c;
                a.VPSE__c = t2t.VPSE__c; 
            }
            if (Terr2Terr_SA.get(a.Agency__c)<>null){
                Territory_Reference__c  t2t = Terr2Terr_SA.get(a.Agency__c);
                a.Agency_Name__c = t2t.AGENCY__c;  


                a.NAIS_VOSS_Mgr__c = t2t.NAIS_VOSS_Mgr__c;
                a.NAIS_VSEN_Mgr__c = t2t.NAIS_VSEN_Mgr__c;
                a.MSO__c = t2t.MSO__c;
                a.PSE_Representative__c = t2t.PSE__c;
                a.PSM__c = t2t.PSM__c;
                a.RMOS__c = t2t.RMOS__c;
                a.VOSS__c = t2t.VOSS__c;
                a.VPSO__c = t2t.RVP__c;
                a.MTSS__c = t2t.MTSS__c;
                a.Xerox_Entity__c = t2t.REGION__c;
                a.Area_Title_t2t__c = t2t.Area_Title__c;      
                a.ASD__c = t2t.ASD__c;
                a.CBM__c = t2t.CBM__c;
                a.VSPM__c = t2t.VSPM__c;
                
                       
}











        
        List<Contact> contactList = new List<Contact>();
   List<Contact> contactList1 = new List<Contact>();
for(Account acc: [SELECT Id,RecordTypeID,(SELECT Id,RecordTypeID,Account.Id FROM Contacts) FROM Account WHERE Id in: Trigger.new]){
   If(acc.Contacts.size()>0 && acc.RecordTypeID =='012E0000000PR3u'){
     contactList.addALL(acc.Contacts);
    }
        
       
        
        for(contact c:contactList){
    If(c.RecordTypeID !='012440000002T6J' && c.Account.Id == acc.Id){
       c.checkbox__c=true;
       contactList1.add(c);
       //a.NAIS_VOSS_Mgr__c = t2t.NAIS_VOSS_Mgr__c;
                //a.NAIS_VSEN_Mgr__c = t2t.NAIS_VSEN_Mgr__c;
                c.CBM__c = a.MSO__c;
               // a.PSE__c = t2t.PSE__c;
              //  a.PSM__c = t2t.PSM__c;
               // a.RVP__c = t2t.RMOS__c;
              //  a.VOSS__c = t2t.VOSS__c;
              //  a.RVP__c = t2t.RVP__c;
               // a.MTSS__c = t2t.MTSS__c;
             //   a.Xerox_Entity__c = t2t.REGION__c;
              //  a.Area_Title_t2t__c = t2t.Area_Title__c;      
              //  a.ASD__c = t2t.ASD__c;
              //  a.CBM__c = t2t.CBM__c;
             //   a.VSPM__c = t2t.VSPM__c
}
}
}
update contactList1;
}
 }      
        
        
        
        
        
        
    
    

}

 
I have a trigger on Account that will update all related Contacts when updated.  I'm receiving the following error:  maximum trigger depth exceeded Account trigger event AfterUpdate Contact trigger event AfterUpdate  Any guidance would be appreciated.  Here is my trigger:
trigger UpdateRelatedContacts on Account (after update){
   List<Contact> contactList = new List<Contact>();
   List<Contact> contactList1 = new List<Contact>();
for(Account acc: [SELECT Id,RecordTypeID,(SELECT Id,RecordTypeID FROM Contacts) FROM Account WHERE Id in: Trigger.new]){
   If(acc.Contacts.size()>0 && (acc.RecordTypeID =='012E0000000PR3u' || acc.RecordTypeID =='012440000002T4h')){
     contactList.addALL(acc.Contacts);
    }
}
for(contact c:contactList){
    If(c.RecordTypeID !='012440000002T6J'){
       c.checkbox__c=true;
       contactList1.add(c);
}

update contactList1;
I currently have a Visual Flow that is launched by a Custom Button:

{!$Site.BaseUrl}/apex/FlowDesigner_Start_NB_Note_Flow?&VarAccountId={!Account.Id}

The button calls on a custom VF Page where the finish location is set - it brings the user back to the Account where the button was clicked from:
 
<apex:page showHeader="False" sidebar="False">
  <flow:interview name="NB_Note_Flow" finishLocation="/{!$CurrentPage.parameters.VarAccountId}">
  <body onload="moveTo(0,0); resizeTo(900,400);">
  </body>
  </flow:interview>
</apex:page>

Everything currently works as originally intended.  What I'd like to do is keep the current finish location as a default, but add an additional finish location if a record is created (in a custom object) through the flow.  This record can be referenced by a variable in the flow, {!DealerProspectVar}.  Is this something that can be done?  Any help is greatly appreciated!

 
I have a trigger on Account that will update all related Contacts when updated.  I'm receiving the following error:  maximum trigger depth exceeded Account trigger event AfterUpdate Contact trigger event AfterUpdate  Any guidance would be appreciated.  Here is my trigger:
trigger UpdateRelatedContacts on Account (after update){
   List<Contact> contactList = new List<Contact>();
   List<Contact> contactList1 = new List<Contact>();
for(Account acc: [SELECT Id,RecordTypeID,(SELECT Id,RecordTypeID FROM Contacts) FROM Account WHERE Id in: Trigger.new]){
   If(acc.Contacts.size()>0 && (acc.RecordTypeID =='012E0000000PR3u' || acc.RecordTypeID =='012440000002T4h')){
     contactList.addALL(acc.Contacts);
    }
}
for(contact c:contactList){
    If(c.RecordTypeID !='012440000002T6J'){
       c.checkbox__c=true;
       contactList1.add(c);
}

update contactList1;
I currently have a Visual Flow that is launched by a Custom Button:

{!$Site.BaseUrl}/apex/FlowDesigner_Start_NB_Note_Flow?&VarAccountId={!Account.Id}

The button calls on a custom VF Page where the finish location is set - it brings the user back to the Account where the button was clicked from:
 
<apex:page showHeader="False" sidebar="False">
  <flow:interview name="NB_Note_Flow" finishLocation="/{!$CurrentPage.parameters.VarAccountId}">
  <body onload="moveTo(0,0); resizeTo(900,400);">
  </body>
  </flow:interview>
</apex:page>

Everything currently works as originally intended.  What I'd like to do is keep the current finish location as a default, but add an additional finish location if a record is created (in a custom object) through the flow.  This record can be referenced by a variable in the flow, {!DealerProspectVar}.  Is this something that can be done?  Any help is greatly appreciated!