I do have a trigger class that updates a custom object with the manager field after the record is created. The trigger is called in "isAfter" context. But when executed I do receive the message as I specified. I checked the code with some debug code and I don't see much record or loops. But still recieve the following error and it doens't execute the method.

20:23:00.167 (8167148120)|FATAL_ERROR|Internal Salesforce.com Error
20:23:00.167 (8167169148)|CUMULATIVE_LIMIT_USAGE 20:23:00.167
(8167169148)|LIMIT_USAGE_FOR_NS|(default)|   Number of SOQL queries:
49 out of 100   Number of query rows: 27187 out of 50000 *******
CLOSE TO LIMIT   Number of SOSL queries: 0 out of 20

Even though it says close to limit, on the debug status it shows

"Internal server error".

Below is the method that does have the issue.

public static void populateBUManagerOnSample(List<Sampling__c>sampling){

                        Map<String,Business_Unit_Managers__c> MapBUMgrs = new Map<String,Business_Unit_Managers__c>();
                        Set<Sampling__c> mySamplingSet = new Set<Sampling__c>();
                        List<Sampling__c> setSamplingList = new List<Sampling__c>(mySamplingSet);

                        System.Debug('CodeDebugging:: Inside BU manager');
                            for(Sampling__c sp: sampling){

                                System.Debug('CodeDebugging:: Inside Sampling loop');
                                id tempUser;
                                Sampling__c s = new Sampling__c (id=sp.id); 

                                List<Business_Unit_Managers__c> lstBUMgrs = [Select b.Product_Line__c ,b.Product_Family__c,b.Object_Type__c, b.Item_Accounting_Class__c, b.Id, b.Business_Unit__c, b.BU_Manager__c, b.BU_Manager1__c, b.BU_Manager2__c, b.BU_Manager3__c, b.BU_Manager4__c From Business_Unit_Managers__c b where b.Object_Type__c='Sample' and Item_Accounting_Class__c = :sp.Business_Unit__c  and Product_Line__c = :sp.Product_Line__c and Product_Family__c = :sp.Product_Family__c];

                                for(Business_Unit_Managers__c bu : lstBUMgrs) {

                                    System.Debug('CodeDebugging:: Inside Business unit loop');
                                    Business_Unit_Managers__c temps = bu;
                                    tempUser = temps.BU_Manager__c;
                                    else if(temps.BU_Manager1__c!=null)
                                    else if(temps.BU_Manager2__c!=null)
                                    else if(temps.BU_Manager3__c!=null)
                                    else if(temps.BU_Manager4__c!=null)
                                    s.BU_Manager__c  =(temps.BU_Manager__c!=null  ? temps.BU_Manager__c :tempUser);
                                    s.BU_Manager1__c =(temps.BU_Manager1__c!=null ? temps.BU_Manager1__c :tempUser);
                                    s.BU_Manager2__c =(temps.BU_Manager2__c!=null ? temps.BU_Manager2__c :tempUser);
                                    s.BU_Manager3__c =(temps.BU_Manager3__c!=null ? temps.BU_Manager3__c :tempUser);
                                    s.BU_Manager4__c =(temps.BU_Manager4__c!=null ? temps.BU_Manager4__c :tempUser);

                            System.Debug('CodeDebugging:: Data to update ' + setSamplingList);
                            update setSamplingList;
                            System.Debug('Product Line! ' + setSamplingList);
                        catch(Exception e){
                            System.Debug('Exception : Not able to update the BU Manager ' + e);

Any idea how to resolve it?


Internal errors are bugs where the platform is hitting a condition that hasn't been coded for. You could work with Salesforce support to identify the exact cause, but that process can take some time.

In this case, if you are confident that the problem is coming from the code you posted, re-writing that code is probably the best way to go on the assumption that the current code is creating an atypical situation for the platform. As hopefully you are aware, the current code violates the bulkification best practice in that it does a query inside a loop. As users add data it is likely that the code will eventually break by exceeding the governor limit. It also looks like it could try to update the same Sampling__c to different values in one update.

Here is an outline of one way to do the re-write:

public static void populateBUManagerOnSample(List<Sampling__c>sampling) {

    Set<String> keys = new Set<String>():
    for(Sampling__c s: sampling) {

    Map<String,Business_Unit_Managers__c> m = new Map<String,Business_Unit_Managers__c>(); 
    for (Business_Unit_Managers__c b: [
            Select Key__c, ...
            From Business_Unit_Managers__c
            where Object_Type__c='Sample'
            and Key__c in :keys
            ]) {
        m.put(m.Key__c, b);

    List<Sampling__c> updates = new List<Sampling__c>();
    for(Sampling__c s: sampling) {
        Business_Unit_Managers__c b = m.get(s.Key__c);
        if (b != null) {
            Id tempUser = ...
            udates.add(new Sampling__c(
                    Id = s.Id,
                    BU_Manager__c = b.BU_Manager__c != null ? b.BU_Manager__c : tempUser,
    update updates;

The above code assumes that you add a formula field (called Key here but use a better name) to both Sampling__c and Business_Unit_Managers__c respectively of:

BusinessUnit__c + '::' + Product_Line__c + '::' + Product_Family__c


Item_Accounting_Class__c + '::' + Product_Line__c + '::' + Product_Family__c

Having that single field on both objects is the trick to allowing simple code to be used to connect the two objects together.

| improve this answer | |
  • There's a hard limit of ten namespaces per transaction. Perhaps they are running afoul of this limit? Kind of odd it's an internal server error though. – sfdcfox Jun 19 '15 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.