• ashish
  • NEWBIE
  • 110 Points
  • Member since 2017

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 32
    Replies
Hello, there!

We have these two processes on Accounts in Process Builder -- one that updates a custom field called "Territory" based on the Billing State Code or the Billing City and/or the Region fields. The other that updates a custom field called "Region" based on the Billing Country field. Both processes have recently been getting the same error notifications as follows:
 
"The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: AccountTrigger: System.LimitException: Apex CPU time limit exceeded. For details, see API Exceptions."

Looks like it is being caused via the Process Builder but I suspect the root cause is the Apex here. Can you please look into this and see if the code needs to be made more efficient or fixed? I've attached the complete Apex trigger code and its test class below for your reference.

Please let me know if you require any further information. Your help will be greatly appreciated!

(My apologies this is a lof of code...)

AccountTrigger
/*******************************************************************************
 * AccountTrigger
 * @Description: Master Trigger for Accounts, which fires on ALL events to
 *               control the order in which trigger actions occur.  Follows the
 *               super trigger best practice from Salesforce:
 * 
 * https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
trigger AccountTrigger on Account (before insert, before update)
{
                                                 // Determine what action is 
                                                 // occurring and when, and
                                                 // pass the correct context
                                                 // variables to the Trigger
                                                 // Handler class where all the
                                                 // actions will take place
    if (Trigger.isBefore && Trigger.isInsert) 
    {
                                                 // Before Insert
        AccountTriggerHandler.beforeInsert(Trigger.new,
                                           Trigger.newMap);
    }
    else if (Trigger.isBefore && Trigger.isUpdate) 
    {
                                                 // Before Update
        AccountTriggerHandler.beforeUpdate(Trigger.new,
                                           Trigger.newMap,
                                           Trigger.old,
                                           Trigger.oldMap);
    }

    /* FOR FRAMEWORK SETUP ONLY. NO ACTIONS ARE TAKEN AT THIS TIME
    else if (Trigger.isBefore && Trigger.isDelete) 
    {
                                                 // Before Delete
        AccountTriggerHandler.beforeDelete(Trigger.new,
                                           Trigger.newMap,
                                           Trigger.old,
                                           Trigger.oldMap);
    }
    else if (Trigger.isAfter && Trigger.isInsert)
    {
                                                 // After Insert
        AccountTriggerHandler.afterInsert(Trigger.new,
                                          Trigger.newMap);
    }
    else if (Trigger.isAfter && Trigger.isUpdate) 
    {
                                                 // After Update
        AccountTriggerHandler.afterUpdate(Trigger.new,
                                          Trigger.newMap,
                                          Trigger.old,
                                          Trigger.oldMap);
    }    
    else if (Trigger.isAfter && Trigger.isDelete) 
    {
                                                 // After Delete
        AccountTriggerHandler.afterDelete(Trigger.new,
                                          Trigger.old);
    }
    else if (Trigger.isAfter && Trigger.isUnDelete) 
    {
                                                 // After UnDelete
        AccountTriggerHandler.afterUnDelete(Trigger.new,
                                            Trigger.old);
    }
    */
    
}

AccountTriggerHandler​
/*******************************************************************************
 * AccountTriggerHandler
 * @Description: Class for handling all Account Trigger functionality.
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
public with sharing class AccountTriggerHandler
{
    /*******************************************************************************
     * beforeInsert
     * @Description: Method for handling all "BeforeInsert" functionality.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static void beforeInsert(List<Account> a_newRecordList,
                                   Map<Id,Account> a_newRecordMap)
    {
        System.debug('*** START: AccountTriggerHandler.beforeInsert()');
        
                                                 // Iterate through the new Account
                                                 // records and grab their SIC Code
                                                 // (if applicable).
        Set<String> sicCodeSet = new Set<String>();
        for (Account a : a_newRecordList)
        {
            if (a.Sic != null && a.Sic != '')
            {
                sicCodeSet.add(a.Sic);
            }
        }
        
                                                 // Do we have a Set of SIC Codes?
        if (!sicCodeSet.isEmpty())
        {
                                                 // Re-Iterate through the new Account
                                                 // records and set their reference to
                                                 // a SIC_Code__c record (if applicable).
            Map<String,Id> sicCodeIdMap = getSICCodeMap(sicCodeSet);
            for (Account a : a_newRecordList)
            {
                if (sicCodeIdMap.containsKey(a.Sic))
                {
                    a.SIC_Code__c = sicCodeIdMap.get(a.Sic);
                }
            }
        }
        
        System.debug('*** END: AccountTriggerHandler.beforeInsert()');
        
    } // End Method: beforeInsert()
    
    /*******************************************************************************
     * beforeUpdate
     * @Description: Method for handling all "Before Update" functionality.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static void beforeUpdate(List<Account> a_newRecordList,
                                   Map<Id,Account> a_newRecordMap,
                                   List<Account> a_oldRecordList,
                                   Map<Id,Account> a_oldRecordMap)
    {
        System.debug('*** START: AccountTriggerHandler.beforeUpdate()');
        
                                                 // Iterate through the updated Account
                                                 // records and grab their SIC Codes
                                                 // (if applicable).
        Set<String> sicCodeSet = new Set<String>();
        for (Account a : a_newRecordList)
        {
                                                 // Was the SIC Code changed?
            if (a.Sic != a_oldRecordMap.get(a.Id).Sic)
            {
                                                 // If the SIC Code was removed, clear
                                                 // the Lookup field.
                if (a.Sic == null || a.Sic == '')
                {
                    a.SIC_Code__c = null;
                }
                else
                {
                    sicCodeSet.add(a.Sic);
                }
            }
        }
        
                                                 // Do we have a Set of SIC Codes?
        if (!sicCodeSet.isEmpty())
        {
                                                 // Re-Iterate through the updated Account
                                                 // records and set their reference to
                                                 // a SIC_Code__c record (if applicable).
            Map<String,Id> sicCodeIdMap = getSICCodeMap(sicCodeSet);
            for (Account a : a_newRecordList)
            {
                if (sicCodeIdMap.containsKey(a.Sic))
                {
                    a.SIC_Code__c = sicCodeIdMap.get(a.Sic);
                }
            }
        }
        
        System.debug('*** END: AccountTriggerHandler.beforeUpdate()');
        
    } // End Method: beforeUpdate()
    
    /*******************************************************************************
     * getSICCodeMap
     * @Description: Method for returning a Map of SIC Code-to-SIC Code Id.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Paramaters: Set<String> a_sicCodeSet
     * @Return: Map<String,Id> returnMap
     * 
     * @Updates: N/A
     *******************************************************************************/
    private static Map<String, Id> getSICCodeMap(Set<String> a_sicCodeSet)
    {
        System.debug('*** START: AccountTriggerHandler.getSICCodeMap()');
        
        Map<String,Id> returnMap = new Map<String,Id>();
        
                                                 // Iterate through the SIC Code records
                                                 // associated with the SIC Codes on the
                                                 // Account records that have been
                                                 // modified. 
        for (SIC_Code__c sc : [SELECT Id,
                                      Name
                               FROM   SIC_Code__c
                               WHERE  Name IN :a_sicCodeSet])
        {
                                                 // This SIC Code is associated with an
                                                 // Account that has been updated, so
                                                 // add it to the Map being returned.
            returnMap.put(sc.Name, sc.Id);
        }
        System.debug('*** returnMap: ' + returnMap);
        
        System.debug('*** END: AccountTriggerHandler.getSICCodeMap()');
        
        return returnMap;
        
    } // End Method: getSICCodeMap()
    
}

AccountTriggerHandlerTest​
/*******************************************************************************
 * AccountTriggerHandlerTest
 * @Description: Test class for AccountTriggerHandler class.
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
@isTest
public class AccountTriggerHandlerTest
{
    private static final String sicCode_Name = '01110000';
    private static final String sicCode_Description = 'WHEAT';

    /*******************************************************************************
     * TestDataSetup
     * @Description: Method to create test data to be used throughout the class.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    @testSetup static void TestDataSetup()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeInsert()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            SIC_Code__c sicCode = new SIC_Code__c();
            sicCode.Name = sicCode_Name;
            sicCode.Description__c = sicCode_Description;
            insert(sicCode);
        }
    }

    /*******************************************************************************
     * test_beforeInsert
     * @Description: Method to test the "beforeInsert" method.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static testMethod void test_beforeInsert()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeInsert()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            Test.startTest();
            
            Account newAccount = new Account();
            newAccount.Name = 'Test Account';
            newAccount.CurrencyIsoCode = 'USD';
            newAccount.Website = 'http://www.somewhere.com/';
            newAccount.Vertical_Market__c = 'Marketplace';
            newAccount.E_Commerce_Solution_US__c = 'Amazon';
            newAccount.AlexaRating__c = '0-10K';
            newAccount.Sic = sicCode_Name;
            insert(newAccount);
            
            Test.stopTest();

            List<Account> newAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            //System.assert(newAccountList.size() > 0, 'Account was NOT created with SIC Code reference');            
        }
        
        System.debug('*** END: AccountTriggerHandlerTest.test_beforeInsert()');
        
    } // End Method: test_afterInsert()
    
    /*******************************************************************************
     * test_beforeUpdate
     * @Description: Method to test the "beforeUpdate" method.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static testMethod void test_beforeUpdate()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeUpdate()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            Test.startTest();

            Account newAccount = new Account();
            newAccount.Name = 'Test Account';
            newAccount.CurrencyIsoCode = 'USD';
            newAccount.Website = 'http://www.somewhere.com/';
            newAccount.Vertical_Market__c = 'Marketplace';
            newAccount.E_Commerce_Solution_US__c = 'Amazon';
            newAccount.AlexaRating__c = '0-10K';
            insert(newAccount);
            
            List<Account> newAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            System.assert(newAccountList.size() == 0, 'Account was created with SIC Code Reference');            

            newAccount.Sic = sicCode_Name;
            update(newAccount);
            
            List<Account> updatedAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            //System.assert(updatedAccountList.size() > 0, 'Account was NOT updated with SIC Code Reference');            

            Test.stopTest();
        }
        
        System.debug('*** END: AccountTriggerHandlerTest.test_beforeUpdate()');
        
    } // End Method: test_beforeUpdate()
    
}

 
All,
I'm attempting to simply invoke my apex class from a trigger instead of the process builder. How do I invoke the following class in my trigger? It doesn't fire, yet my debug log shows the objIds.size() = 1.

Class:
global class WR_UpdateGeo {
   @InvocableMethod
   
   public static void getAccountIds(List<Id> objIds) {
     
      //Get the sObject token from the first ID
      Schema.SObjectType token = objIds[0].getSObjectType();
      Schema.DescribeSObjectResult dr = token.getDescribe();
       
      String Scountry = 'country';   
      if (dr.getName() == 'account')
         Scountry = 'BillingCountry';  
      
      // Construct query dynamically.
      String queryString = 'SELECT id, ' + Scountry + ' FROM ' + dr.getName() + ' WHERE ';
      for(ID objId : objIds) {
            queryString += 'Id=\'' + objId + '\' OR ';
          }  
            
      queryString = queryString.subString(0, queryString.length() - 4);
      sObject[] objDBList = Database.query(queryString);
       
       // GEO
       String geo = '';
        List<Country_GEO_Mapping__c> lst_countryGeoMapping = [SELECT Country_Name__c, GEO_Name__c FROM Country_GEO_Mapping__c ];
        Map<String, String> map_countryGeoMapping = new Map<String, String>();
      
        for(Country_GEO_Mapping__c    cg: lst_CountryGeoMapping){
            map_countryGeoMapping.put(cg.Country_Name__c, cg.GEO_Name__c);
          }
            
       // Update the GEO on the sObjects
       for(Integer i = 0; i < objDBList.size(); i++) {
          
          if (dr.getName() == 'account') {
              if(map_countryGeoMapping.containsKey(String.valueOf(objDBList[i].get('BillingCountry')))) {
                 geo = map_countryGeoMapping.get(String.valueOf(objDBList[i].get('BillingCountry'))); }
                 objDBList[i].put('GEO__c', geo);
               }
              //geo = 'APAC';}
             //objDBList[i].put('GEO__c', Utility_Class.FindGeoFromCountry(String.valueOf(objDBList[i].get('BillingCountry'))));
           
          else {
             if(map_countryGeoMapping.containsKey(String.valueOf(objDBList[i].get('country')))) {
                 geo = map_countryGeoMapping.get(String.valueOf(objDBList[i].get('country')));  }
                 objDBList[i].put('GEO__c', geo);
               }
             //objDBList[i].put('GEO__c', Utility_Class.FindGeoFromCountry(String.valueOf(objDBList[i].get('country')))); 
        }       
        
       Database.SaveResult[] srList = Database.update(objDBList, false);
    }
}

Trigger:
trigger WR_BeforeLead on Lead (before insert, before update) {
    List<Id> objIds = new List<Id>();

    if (Trigger.isBefore && Trigger.isUpdate) {
        for(Lead l : Trigger.New){
			if(l.Id != null) {
				objIds.add(l.Id);
			}
		}

		if(objIds.size() > 0){
			System.debug(objIds.size());
			WR_UpdateGeo.getAccountIds(objIds);
		}
	}
}

public class Task08 {
     public string keyword{get;set;}
     Set<Account> sette=new Set<Account>(); 
      public Task08(){
      
      sette=[SELECT Name FROM Account ];
      }
     public pagereference Search(){
    
        //sette=[SELECT Name, id,Course_Name__c FROM Group__c ];
         return null;
     }
}
Hello, there!

We have these two processes on Accounts in Process Builder -- one that updates a custom field called "Territory" based on the Billing State Code or the Billing City and/or the Region fields. The other that updates a custom field called "Region" based on the Billing Country field. Both processes have recently been getting the same error notifications as follows:
 
"The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: AccountTrigger: System.LimitException: Apex CPU time limit exceeded. For details, see API Exceptions."

Looks like it is being caused via the Process Builder but I suspect the root cause is the Apex here. Can you please look into this and see if the code needs to be made more efficient or fixed? I've attached the complete Apex trigger code and its test class below for your reference.

Please let me know if you require any further information. Your help will be greatly appreciated!

(My apologies this is a lof of code...)

AccountTrigger
/*******************************************************************************
 * AccountTrigger
 * @Description: Master Trigger for Accounts, which fires on ALL events to
 *               control the order in which trigger actions occur.  Follows the
 *               super trigger best practice from Salesforce:
 * 
 * https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
trigger AccountTrigger on Account (before insert, before update)
{
                                                 // Determine what action is 
                                                 // occurring and when, and
                                                 // pass the correct context
                                                 // variables to the Trigger
                                                 // Handler class where all the
                                                 // actions will take place
    if (Trigger.isBefore && Trigger.isInsert) 
    {
                                                 // Before Insert
        AccountTriggerHandler.beforeInsert(Trigger.new,
                                           Trigger.newMap);
    }
    else if (Trigger.isBefore && Trigger.isUpdate) 
    {
                                                 // Before Update
        AccountTriggerHandler.beforeUpdate(Trigger.new,
                                           Trigger.newMap,
                                           Trigger.old,
                                           Trigger.oldMap);
    }

    /* FOR FRAMEWORK SETUP ONLY. NO ACTIONS ARE TAKEN AT THIS TIME
    else if (Trigger.isBefore && Trigger.isDelete) 
    {
                                                 // Before Delete
        AccountTriggerHandler.beforeDelete(Trigger.new,
                                           Trigger.newMap,
                                           Trigger.old,
                                           Trigger.oldMap);
    }
    else if (Trigger.isAfter && Trigger.isInsert)
    {
                                                 // After Insert
        AccountTriggerHandler.afterInsert(Trigger.new,
                                          Trigger.newMap);
    }
    else if (Trigger.isAfter && Trigger.isUpdate) 
    {
                                                 // After Update
        AccountTriggerHandler.afterUpdate(Trigger.new,
                                          Trigger.newMap,
                                          Trigger.old,
                                          Trigger.oldMap);
    }    
    else if (Trigger.isAfter && Trigger.isDelete) 
    {
                                                 // After Delete
        AccountTriggerHandler.afterDelete(Trigger.new,
                                          Trigger.old);
    }
    else if (Trigger.isAfter && Trigger.isUnDelete) 
    {
                                                 // After UnDelete
        AccountTriggerHandler.afterUnDelete(Trigger.new,
                                            Trigger.old);
    }
    */
    
}

AccountTriggerHandler​
/*******************************************************************************
 * AccountTriggerHandler
 * @Description: Class for handling all Account Trigger functionality.
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
public with sharing class AccountTriggerHandler
{
    /*******************************************************************************
     * beforeInsert
     * @Description: Method for handling all "BeforeInsert" functionality.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static void beforeInsert(List<Account> a_newRecordList,
                                   Map<Id,Account> a_newRecordMap)
    {
        System.debug('*** START: AccountTriggerHandler.beforeInsert()');
        
                                                 // Iterate through the new Account
                                                 // records and grab their SIC Code
                                                 // (if applicable).
        Set<String> sicCodeSet = new Set<String>();
        for (Account a : a_newRecordList)
        {
            if (a.Sic != null && a.Sic != '')
            {
                sicCodeSet.add(a.Sic);
            }
        }
        
                                                 // Do we have a Set of SIC Codes?
        if (!sicCodeSet.isEmpty())
        {
                                                 // Re-Iterate through the new Account
                                                 // records and set their reference to
                                                 // a SIC_Code__c record (if applicable).
            Map<String,Id> sicCodeIdMap = getSICCodeMap(sicCodeSet);
            for (Account a : a_newRecordList)
            {
                if (sicCodeIdMap.containsKey(a.Sic))
                {
                    a.SIC_Code__c = sicCodeIdMap.get(a.Sic);
                }
            }
        }
        
        System.debug('*** END: AccountTriggerHandler.beforeInsert()');
        
    } // End Method: beforeInsert()
    
    /*******************************************************************************
     * beforeUpdate
     * @Description: Method for handling all "Before Update" functionality.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static void beforeUpdate(List<Account> a_newRecordList,
                                   Map<Id,Account> a_newRecordMap,
                                   List<Account> a_oldRecordList,
                                   Map<Id,Account> a_oldRecordMap)
    {
        System.debug('*** START: AccountTriggerHandler.beforeUpdate()');
        
                                                 // Iterate through the updated Account
                                                 // records and grab their SIC Codes
                                                 // (if applicable).
        Set<String> sicCodeSet = new Set<String>();
        for (Account a : a_newRecordList)
        {
                                                 // Was the SIC Code changed?
            if (a.Sic != a_oldRecordMap.get(a.Id).Sic)
            {
                                                 // If the SIC Code was removed, clear
                                                 // the Lookup field.
                if (a.Sic == null || a.Sic == '')
                {
                    a.SIC_Code__c = null;
                }
                else
                {
                    sicCodeSet.add(a.Sic);
                }
            }
        }
        
                                                 // Do we have a Set of SIC Codes?
        if (!sicCodeSet.isEmpty())
        {
                                                 // Re-Iterate through the updated Account
                                                 // records and set their reference to
                                                 // a SIC_Code__c record (if applicable).
            Map<String,Id> sicCodeIdMap = getSICCodeMap(sicCodeSet);
            for (Account a : a_newRecordList)
            {
                if (sicCodeIdMap.containsKey(a.Sic))
                {
                    a.SIC_Code__c = sicCodeIdMap.get(a.Sic);
                }
            }
        }
        
        System.debug('*** END: AccountTriggerHandler.beforeUpdate()');
        
    } // End Method: beforeUpdate()
    
    /*******************************************************************************
     * getSICCodeMap
     * @Description: Method for returning a Map of SIC Code-to-SIC Code Id.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Paramaters: Set<String> a_sicCodeSet
     * @Return: Map<String,Id> returnMap
     * 
     * @Updates: N/A
     *******************************************************************************/
    private static Map<String, Id> getSICCodeMap(Set<String> a_sicCodeSet)
    {
        System.debug('*** START: AccountTriggerHandler.getSICCodeMap()');
        
        Map<String,Id> returnMap = new Map<String,Id>();
        
                                                 // Iterate through the SIC Code records
                                                 // associated with the SIC Codes on the
                                                 // Account records that have been
                                                 // modified. 
        for (SIC_Code__c sc : [SELECT Id,
                                      Name
                               FROM   SIC_Code__c
                               WHERE  Name IN :a_sicCodeSet])
        {
                                                 // This SIC Code is associated with an
                                                 // Account that has been updated, so
                                                 // add it to the Map being returned.
            returnMap.put(sc.Name, sc.Id);
        }
        System.debug('*** returnMap: ' + returnMap);
        
        System.debug('*** END: AccountTriggerHandler.getSICCodeMap()');
        
        return returnMap;
        
    } // End Method: getSICCodeMap()
    
}

AccountTriggerHandlerTest​
/*******************************************************************************
 * AccountTriggerHandlerTest
 * @Description: Test class for AccountTriggerHandler class.
 * 
 * @Date: 12/15/2015
 * @Author: Jason Flippen (Demand Chain Systems)
 * 
 * @Updates: N/A
 *******************************************************************************/
@isTest
public class AccountTriggerHandlerTest
{
    private static final String sicCode_Name = '01110000';
    private static final String sicCode_Description = 'WHEAT';

    /*******************************************************************************
     * TestDataSetup
     * @Description: Method to create test data to be used throughout the class.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    @testSetup static void TestDataSetup()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeInsert()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            SIC_Code__c sicCode = new SIC_Code__c();
            sicCode.Name = sicCode_Name;
            sicCode.Description__c = sicCode_Description;
            insert(sicCode);
        }
    }

    /*******************************************************************************
     * test_beforeInsert
     * @Description: Method to test the "beforeInsert" method.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static testMethod void test_beforeInsert()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeInsert()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            Test.startTest();
            
            Account newAccount = new Account();
            newAccount.Name = 'Test Account';
            newAccount.CurrencyIsoCode = 'USD';
            newAccount.Website = 'http://www.somewhere.com/';
            newAccount.Vertical_Market__c = 'Marketplace';
            newAccount.E_Commerce_Solution_US__c = 'Amazon';
            newAccount.AlexaRating__c = '0-10K';
            newAccount.Sic = sicCode_Name;
            insert(newAccount);
            
            Test.stopTest();

            List<Account> newAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            //System.assert(newAccountList.size() > 0, 'Account was NOT created with SIC Code reference');            
        }
        
        System.debug('*** END: AccountTriggerHandlerTest.test_beforeInsert()');
        
    } // End Method: test_afterInsert()
    
    /*******************************************************************************
     * test_beforeUpdate
     * @Description: Method to test the "beforeUpdate" method.
     * 
     * @Date: 12/15/2015
     * @Author: Jason Flippen (Demand Chain Systems)
     * 
     * @Updates: N/A
     *******************************************************************************/
    public static testMethod void test_beforeUpdate()
    {
        System.debug('*** START: AccountTriggerHandlerTest.test_beforeUpdate()');
        
        Id sysAdminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
        Id execTeamRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'ExecutiveTeam'].Id;
        
                                                 // Create System Administrator User.
        User adminUser = new User();
        adminUser.LastName = 'dr' + Crypto.getRandomInteger();
        adminUser.Email = adminUser.LastName + '@drtest.com';
        adminUser.UserName = adminUser.Email;
        adminUser.Alias = String.valueOf(adminUser.LastName.SubString(0,8));
        adminUser.ProfileId = sysAdminProfileId;
        adminUser.UserRoleId = execTeamRoleId;
        adminUser.LocaleSidKey = 'en_US';
        adminUser.LanguageLocaleKey = 'en_US';
        adminUser.TimeZoneSidKey = 'America/Los_Angeles';
        adminUser.EmailEncodingKey = 'UTF-8';
        insert(adminUser);
        
        system.runAs(adminUser)
        {
            Test.startTest();

            Account newAccount = new Account();
            newAccount.Name = 'Test Account';
            newAccount.CurrencyIsoCode = 'USD';
            newAccount.Website = 'http://www.somewhere.com/';
            newAccount.Vertical_Market__c = 'Marketplace';
            newAccount.E_Commerce_Solution_US__c = 'Amazon';
            newAccount.AlexaRating__c = '0-10K';
            insert(newAccount);
            
            List<Account> newAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            System.assert(newAccountList.size() == 0, 'Account was created with SIC Code Reference');            

            newAccount.Sic = sicCode_Name;
            update(newAccount);
            
            List<Account> updatedAccountList = [SELECT Id, SICDescription__c FROM Account WHERE Id = :newAccount.Id AND SICDescription__c = :sicCode_Description];
            //System.assert(updatedAccountList.size() > 0, 'Account was NOT updated with SIC Code Reference');            

            Test.stopTest();
        }
        
        System.debug('*** END: AccountTriggerHandlerTest.test_beforeUpdate()');
        
    } // End Method: test_beforeUpdate()
    
}

 
Hi,

Consider two objects A and B..
B is in the related list of A. 
Assume that there is a record in object B is created with Name (ABC).
So whenever another record is created on object B with Name other than (ABC), i want to delete the record named (ABC).

Could you assist me on setting up this configuration.

Many Thanks !
Hi All,
when i try to delete a account recordtype i am assigning the records to existing recordtype.in this case account trigger is not firing.
can anyone suggest what is the reason.

Or is there any way to track which recordtype is going to be deleted and to which recordtype the records will be assigned?
Thanks
Sindhu
seeing this error in console.
and a parameter is not getting passed to AuraEnabled method while developing lightning Application
Hello all,

 i have one requirement to identify duplicate records from custom object dupRecObj__C

 in this object i have 2 lakh records, i have almost 8 fileds, including dateTime and date fields. i need to compare each record with all other records if all 8 fields matches. it will be duplicate field. how can i achive this scenario. can any one help me on it.

thanks 
Vijendhar 
All,
I'm attempting to simply invoke my apex class from a trigger instead of the process builder. How do I invoke the following class in my trigger? It doesn't fire, yet my debug log shows the objIds.size() = 1.

Class:
global class WR_UpdateGeo {
   @InvocableMethod
   
   public static void getAccountIds(List<Id> objIds) {
     
      //Get the sObject token from the first ID
      Schema.SObjectType token = objIds[0].getSObjectType();
      Schema.DescribeSObjectResult dr = token.getDescribe();
       
      String Scountry = 'country';   
      if (dr.getName() == 'account')
         Scountry = 'BillingCountry';  
      
      // Construct query dynamically.
      String queryString = 'SELECT id, ' + Scountry + ' FROM ' + dr.getName() + ' WHERE ';
      for(ID objId : objIds) {
            queryString += 'Id=\'' + objId + '\' OR ';
          }  
            
      queryString = queryString.subString(0, queryString.length() - 4);
      sObject[] objDBList = Database.query(queryString);
       
       // GEO
       String geo = '';
        List<Country_GEO_Mapping__c> lst_countryGeoMapping = [SELECT Country_Name__c, GEO_Name__c FROM Country_GEO_Mapping__c ];
        Map<String, String> map_countryGeoMapping = new Map<String, String>();
      
        for(Country_GEO_Mapping__c    cg: lst_CountryGeoMapping){
            map_countryGeoMapping.put(cg.Country_Name__c, cg.GEO_Name__c);
          }
            
       // Update the GEO on the sObjects
       for(Integer i = 0; i < objDBList.size(); i++) {
          
          if (dr.getName() == 'account') {
              if(map_countryGeoMapping.containsKey(String.valueOf(objDBList[i].get('BillingCountry')))) {
                 geo = map_countryGeoMapping.get(String.valueOf(objDBList[i].get('BillingCountry'))); }
                 objDBList[i].put('GEO__c', geo);
               }
              //geo = 'APAC';}
             //objDBList[i].put('GEO__c', Utility_Class.FindGeoFromCountry(String.valueOf(objDBList[i].get('BillingCountry'))));
           
          else {
             if(map_countryGeoMapping.containsKey(String.valueOf(objDBList[i].get('country')))) {
                 geo = map_countryGeoMapping.get(String.valueOf(objDBList[i].get('country')));  }
                 objDBList[i].put('GEO__c', geo);
               }
             //objDBList[i].put('GEO__c', Utility_Class.FindGeoFromCountry(String.valueOf(objDBList[i].get('country')))); 
        }       
        
       Database.SaveResult[] srList = Database.update(objDBList, false);
    }
}

Trigger:
trigger WR_BeforeLead on Lead (before insert, before update) {
    List<Id> objIds = new List<Id>();

    if (Trigger.isBefore && Trigger.isUpdate) {
        for(Lead l : Trigger.New){
			if(l.Id != null) {
				objIds.add(l.Id);
			}
		}

		if(objIds.size() > 0){
			System.debug(objIds.size());
			WR_UpdateGeo.getAccountIds(objIds);
		}
	}
}

I have two objects Resolutions and Claims

Resolution has a checkbox type attribute and I need that when it is selected, a field named "State" of the object Claims changes to "Closed"

I have used valuation rules but I have not been able to achieve this, how else can I achieve it without needing to use apex code?

Regards and thanks
public class Task08 {
     public string keyword{get;set;}
     Set<Account> sette=new Set<Account>(); 
      public Task08(){
      
      sette=[SELECT Name FROM Account ];
      }
     public pagereference Search(){
    
        //sette=[SELECT Name, id,Course_Name__c FROM Group__c ];
         return null;
     }
}
HI Experts 

This is my reuirement.

i have Follow button. for ex: i want count  avalue only one time but here same user clicked multipulle times on button that time i don't want increment count value. please help me how to i will write a logic in method.

 
<apex:commandButton id="CommandButton1" value="Follow" action="{!followOwner}"/>



public Integer followingCount{get;set;}

//Constructor
public userData (ApexPages.StandardController stdController) {
    UserId = UserInfo.getUserId();
    GetCount();
}

 //Method
 public void GetCount() {

 List<User> following = [SELECT Id, Name,title, SmallPhotoUrl FROM User WHERE Id =:parentsetid AND Id !=:u.id order by name]; 
    followingCount = following.size();
 }


Thanks in Advance,
Chanti
 
<apex:page standardController="Case" showHeader="false" >
    <apex:form >
        <apex:pageBlock title="Case Status">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Case.Status}"/>
                <apex:inputField value="{!Case.Reason}"/>
                <apex:inputField value="{!Case.Priority}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="save"/> 
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

when giving reason and status for the case object and saving it. this saved record should be displayed in another new VF page
Hi, 
we still work in salesforc classic. 

I would like to create a new button in the open activity section.

.User-added image

When clicking on the button, a new event should open up with a prefilled  titel. More or less the same functionality as if i click on new event, but with a different layout.
I tried to do this but ended up in a negative result.
Is there an easy way to do this without much programming ?
Thanks in advance




 
 Hi,
I have a custom billing_account__c object on which we can create cases of particular record type.
I am giving case creation function through a custom button.
Here is the challenge am trying to solve.
If there is a open case already existing on billing_account__c on that record type, I would like to close new case and if does not
Exist I will go ahead and create a case.
I am trying this using triggers but since new could not find a way.
Can someone help with this!?
Regards 
Vijay