0

I have a lightning component that is working fine with System Administrator user but not with everyone else.

This is my code:

helper.js:

checkPreActionStatus : function(component){
    var result;
    var apexLIST = component.get("v.apexLIST");
    var header = component.get("v.header");
    var index = component.get("v.index");
    var headeraction = header.actionHeaderPreStepLIST[index];
    var fieldConditionLIST = component.get("v.fieldConditionLIST");
    var historyStatusByHeaderIdMAP = component.get("v.historyStatusByHeaderIdMAP");
    var action = component.get("c.checkActionConditions");
    action.setParams({
        "recordId" : component.get("v.recordId"),
        "logicConditions" : headeraction.actionHeaderStepAttributeLIST.logicConditions,
        "message" : null,
        "conditionLIST" : fieldConditionLIST.length > 0 ? fieldConditionLIST : null,
        "parentAction" : header.hasOwnProperty('parentAction') ? header.parentAction : null,
        "apexJSON" : !$A.util.isEmpty(apexLIST) ? JSON.stringify(apexLIST) : null
    }); 
    console.log('***action params: ' + JSON.stringify(action.getParams()));
    action.setCallback(this, function(response){
        if(response.getState() === 'SUCCESS'){
            result = response.getReturnValue();
            console.log('****resultpre: ' + JSON.stringify(result));
            var conditionSuccessLIST = result.hasOwnProperty('conditionSuccessLIST') ? result.conditionSuccessLIST : null;
            //Success
            if(result.success){
                component.set("v.apexLIST", []);
                component.set("v.fieldConditionLIST", []);
                component.set("v.index", index + 1);
                this.fillConditionSuccessMap(component, conditionSuccessLIST, headeraction, header, false);
                //Recall header validation for new actions or end of cycle
                //this.validateHeader(component);    
            }
            //Error
            else{
                component.set("v.apexLIST", []);
                component.set("v.fieldConditionLIST", []);
                historyStatusByHeaderIdMAP[header.referenceId] = 'NOT OK';  
                component.set("v.historyStatusByHeaderIdMAP", historyStatusByHeaderIdMAP);
                component.set("v.index", 0);
                component.set("v.headerIndex", 0);
                this.fillConditionSuccessMap(component, conditionSuccessLIST, headeraction, header, true);
                //this.recordHeaderHistoryEntries(component);  
            }
        }   
        //Error
        else{
            console.log('****record error: ' + JSON.stringify(response.getError()[0]));
            component.set("v.apexLIST", []);
            component.set("v.fieldConditionLIST", []);
            historyStatusByHeaderIdMAP[header.referenceId] = 'NOT OK';  
            component.set("v.historyStatusByHeaderIdMAP", historyStatusByHeaderIdMAP);
            component.set("v.index", 0);
            component.set("v.headerIndex", 0);
            this.fillConditionSuccessMap(component, conditionSuccessLIST, headeraction, header, true);
            //this.recordHeaderHistoryEntries(component);       
        }
    });
    $A.enqueueAction(action);    
},

apex controller:

@AuraEnabled
public static BI_LEX_GenericApprovalActionControl.response checkActionConditions(String recordId, String logicConditions, String message, List<BI_LEX_Condition__c> conditionLIST, String parentAction, String apexJSON){
    BI_LEX_GenericApprovalActionControl.response result = new BI_LEX_GenericApprovalActionControl.response();
    String query;
    String auxValue;
    String auxString;
    Integer auxNumber;
    List<SObject> checkLIST;
    Boolean auxBoolean;
    Boolean byPassParent = true;
    Boolean emptyLogic = (logicConditions != null && !String.isEmpty(logicConditions)) ? false : true;
    System.debug('***apexJSON: ' + apexJSON);
    BI_LEX_Condition__c auxCondition;
    //Map of condition result by BI_LEX_Numero_condicion__c or generic index (if logicConditions has no value)
    Map<String,Boolean> conditionByNumberMAP = new Map<String,Boolean>();
    //For boolean values check
    Set<String> booleanSET = new Set<String>{'true','false'};
    //Check parent action if found
    if(parentAction != null){
        result = BI_LEX_GenericApprovalActionControl.parentActionCheck(parentAction);
        byPassParent = result.success;
    }
    //No parent action or parent action previously approved => DEPRECATED FOR NOW
    if(byPassParent){
        //Get apex method results if found
        List<BI_LEX_GenericApprovalActionControl.apexMethodConditionWrapper> apexMethodLIST = apexJSON != null ? (List<BI_LEX_GenericApprovalActionControl.apexMethodConditionWrapper>) JSON.deserialize(apexJSON, List<BI_LEX_GenericApprovalActionControl.apexMethodConditionWrapper>.class) : new List<BI_LEX_GenericApprovalActionControl.apexMethodConditionWrapper>();
        if(!apexMethodLIST.isEmpty()){
            for(Integer a=0; a<apexMethodLIST.size(); a++){
                auxNumber = (!emptyLogic && apexMethodLIST[a].record.BI_LEX_Numero_condicion__c != null) ? (Integer)apexMethodLIST[a].record.BI_LEX_Numero_condicion__c : a;
                conditionByNumberMAP.put(String.valueOf(auxNumber), apexMethodLIST[a].success);
            }       
        }
        //Check record conditions individually
        if(conditionLIST != null && !conditionLIST.isEmpty()){
            query = 'SELECT Id';
            Set<String> fieldSET = new Set<String>();
            //Retrieve fields for query
            for(BI_LEX_Condition__c cd : conditionLIST){
                fieldSET.add(cd.BI_LEX_FieldAPIName__c);     
            }
            query += ', ' + String.join(new List<String>(fieldSET), ', ');
            query = (query.contains(', ') ? query.removeEnd(', ') : '') + ' FROM ' + Id.valueOf(recordId).getSObjectType().getDescribe().getName() + ' WHERE Id = :recordId';
            checkLIST = Database.query(query);
            //Check conditions for fields
            for(Integer cn=0; cn<conditionLIST.size();cn++){
                auxCondition = conditionLIST[cn];
                switch on auxCondition.BI_LEX_ConditionOperator__c{
                    //Equals
                    when 'EQUALS','NOT EQUALS'{
                        //Number
                        if(auxCondition.BI_LEX_FieldValue__c.isNumeric()){
                            auxBoolean = Integer.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c)) == Integer.valueOf(auxCondition.BI_LEX_FieldValue__c);    
                        }
                        //Boolean
                        else if(booleanSET.contains(auxCondition.BI_LEX_FieldValue__c)){
                            auxBoolean = String.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c.toLowerCase())) == String.valueOf(auxCondition.BI_LEX_FieldValue__c.toLowerCase());      
                        }
                        //Rest of cases
                        else{
                            auxBoolean = String.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c)) == String.valueOf(auxCondition.BI_LEX_FieldValue__c);   
                        }
                        System.debug('***auxBool: ' + auxBoolean + ' ---- ' + String.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c)) + ' --- ' + String.valueOf(auxCondition.BI_LEX_FieldValue__c));
                        auxBoolean = auxCondition.BI_LEX_ConditionOperator__c == 'EQUALS' ? auxBoolean : !auxBoolean;
                    }   
                    //Greater
                    when 'MORE THAN'{
                        auxBoolean = Integer.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c)) > Integer.valueOf(auxCondition.BI_LEX_FieldValue__c);     
                    }
                    //Lesser
                    when 'LESS THAN'{
                        auxBoolean = Integer.valueOf(checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c)) < Integer.valueOf(auxCondition.BI_LEX_FieldValue__c);    
                    }
                    //Null
                    when 'IS NULL'{
                        auxBoolean = checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c) == null;     
                    }
                    //Not null
                    when 'NOT NULL'{
                        auxBoolean = checkLIST[0].get(auxCondition.BI_LEX_FieldAPIName__c) != null;    
                    }
                }
                //Add condition success to map
                auxNumber = (!emptyLogic && auxCondition.BI_LEX_Numero_condicion__c != null) ? (Integer)auxCondition.BI_LEX_Numero_condicion__c : cn;
                conditionByNumberMAP.put(String.valueOf(auxNumber), auxBoolean);
                //New wrapper record
                apexMethodLIST.add(new BI_LEX_GenericApprovalActionControl.apexMethodConditionWrapper(auxCondition, auxBoolean));
            }
        }
        //Check conditions logic
        if(!conditionByNumberMAP.isEmpty()){
            String logicAction;
            Boolean checkResult;
            List<String> charLIST;
            //AND
            if(emptyLogic){
                for(String key : conditionByNumberMAP.keySet()){
                    System.debug('***key: ' + key);
                    checkResult = checkResult == null ? conditionByNumberMAP.get(key) : (checkResult && conditionByNumberMAP.get(key));
                }
                System.debug('****check: ' + checkResult);
            }
            //Follow logic steps
            else{
                logicConditions = logicConditions.replace(' ','').replace('AND','A').replace('OR','O').removeStart('(').removeEnd(')');
                charLIST = logicConditions.split('');
                //Encapsuled check
                /*if(logicConditions.contains('(')){ //to do
                    result.success = true; //to do    
                }
                else{
                    charLIST = logicConditions.split('');
                    for(Integer ch=0; ch<charLIST.size(); ch++){
                        //Condition number
                        if(charLIST[ch].isNumeric()){
                            auxBoolean = conditionByNumberMAP.get(charLIST[ch]);
                            checkResult = logicAction != null ? (logicAction == 'A' ? (checkResult && auxBoolean) : (checkResult || auxBoolean)) : (checkResult != null ? checkResult : auxBoolean);
                        }
                        //Get action for check
                        else{
                            logicAction = charLIST[ch];
                        }
                    }
                }*/
                checkResult = BI_LEX_GenericApprovalActionControl.runLogicConditions(0, charLIST, conditionByNumberMAP).result;
            }
            result.success = checkResult != null ? checkResult : false;
            result.conditionSuccessLIST = apexMethodLIST;
        }
        //No conditions to check
        else{
            result.success = true;    
        }
    }
    return result;
}

Class is without sharing and when calling with non-System Administrator user it retrieves 'Internal error. Error Id: 1957360240-224067 (-1314478013)' but then no error found in debug logs.

  • Seems like some kind of permission issue, try adding a try catch inside your controller where you would be able to see proper error message and stack trace instead of a Gack Id – Raul May 20 at 11:41
  • @Raul I tried adding try catch but still retrieves the same – molinet May 20 at 12:46

Your Answer

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

Browse other questions tagged or ask your own question.