Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] InternalExecutionError when running getsObjectConfigs method #1338

Closed
RonanWilliams1 opened this issue Jan 31, 2024 · 2 comments
Closed
Labels
BUG P3 Rarely Malfunction duplicate This issue or pull request already exists SFGE Issues related to the Salesforce Graph Engine

Comments

@RonanWilliams1
Copy link

Description:

Graph Engine identified your source and sink, but you must manually verify that you have a sanitizer in this path. Then, add an engine directive to skip the path. Next, create a Github issue for the Code Analyzer team that includes the error and stack trace. After we fix this issue, check the Code Analyzer release notes for more info. Error and stacktrace: UnexpectedException: ApexStringValue{ value=Optional.empty} ApexValue(ApexStringValue) {status=INITIALIZED, declarationVertex=VariableDeclaration{properties={FirstChild=false, BeginLine=464, Type=String, DefiningType_CaseSafe=relatablecore, LastChild=true, DefiningType=RelatableCore, EndLine=464, Name_CaseSafe=namefield, childIdx=1, BeginColumn=16, Name=nameField}}, valueVertex=LiteralExpression{properties={FirstChild=true, BeginLine=464, DefiningType_CaseSafe=relatablecore, LastChild=false, DefiningType=RelatableCore, EndLine=464, childIdx=0, LiteralType=NULL, BeginColumn=28}}, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}: com.salesforce.graph.ops.ApexValueUtil.getTypeValue(ApexValueUtil.java:376);com.salesforce.graph.ops.ApexValueUtil.convertApexValueToString(ApexValueUtil.java:305);com.salesforce.rules.fls.apex.operations.FlsValidationRepresentation.addField(FlsValidationRepresentation.java:122);com.salesforce.rules.fls.apex.operations.FlsValidationRepresentation.addField(FlsValidationRepresentation.java:114);com.salesforce.rules.fls.apex.operations.SchemaBasedValidationAnalyzer.convert(SchemaBasedValidationAnalyzer.java:185);com.salesforce.rules.fls.apex.operations.SchemaBasedValidationAnalyzer.checkForValidation(SchemaBasedValidationAnalyzer.java:77)

Method code where the error occurs:

`@AuraEnabled
public static List getsObjectConfigs(List sObjectTypes, Boolean allowInlineEditing){

    List<Object> sObjectConfigs = new List<Object>();

    Map<String,Object> sharingSettings = new Map<String,Object>();

    for (Object sObj : sObjectTypes){
        Map<String,Object> sObjectMap = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(sObj));
        String childObjectName = (String)sObjectMap.get('name');
        sharingSettings.put(childObjectName,null);
    }

    List<EntityDefinition> entities = [
        SELECT QualifiedApiName, 
            InternalSharingModel
        FROM EntityDefinition
        WHERE QualifiedApiName IN :sharingSettings.keySet()
        WITH USER_MODE
    ];

    for (EntityDefinition e : entities){
        sharingSettings.put(e.QualifiedApiName,e.InternalSharingModel);
    }

    Set<String> attachableTypes = RelatableUtilities.getAttachableTypes();

    for (Object sObj : sObjectTypes){
        Map<String,Object> sObjectMap = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(sObj));

        String childObjectName = (String)sObjectMap.get('name');
        String childObjectLabel = (String)sObjectMap.get('label');
        String lookupField = (String)sObjectMap.get('field');
        Boolean isInline = (Boolean)sObjectMap.get('inline'); 
        Boolean sObjectAccessible = RelatableUtilities.sObjectAccessible(childObjectName);
        Boolean sObjectCreatable = RelatableUtilities.sObjectCreatable(childObjectName);
        Boolean sObjectEditable = RelatableUtilities.sObjectEditable(childObjectName);
        Boolean isUIAPIEnabled = RelatableUtilities.isUIAPIEnabled(childObjectName);

        Map<String,Object> sObjectConfig = new Map<String,Object>();
        sObjectConfig.put('label',childObjectLabel);
        sObjectConfig.put('name',childObjectName);
        sObjectConfig.put('value',childObjectName + '-' + lookupField);
        sObjectConfig.put('lookupField',lookupField);
        sObjectConfig.put('sharing',sharingSettings.get(childObjectName));
        sObjectConfig.put('attachments',attachableTypes.contains(childObjectName));
        sObjectConfig.put('inline',isInline);
        sObjectConfig.put('accessible',sObjectAccessible);
        sObjectConfig.put('creatable',sObjectCreatable);
        sObjectConfig.put('createRecordEnabled',RelatableUtilities.isForceCreateRecordEnabled(childObjectName));
        sObjectConfig.put('editable',sObjectEditable);
        sObjectConfig.put('deletable',RelatableUtilities.sObjectDeletable(childObjectName));
        sObjectConfig.put('UIAPIEnabled',isUIAPIEnabled);

        String iconType = (String)sObjectMap.get('icontype');
        String icon = (String)sObjectMap.get('icon');
        String iconName = iconType + ':' + icon;

        if (String.isBlank(iconType)){
            iconName = RelatableUtilities.getIconName(childObjectName);
        }

        sObjectConfig.put('icon',iconName);

        if (sObjectCreatable){
            Schema.DescribeSObjectResult r = Schema.getGlobalDescribe().get(childObjectName).getDescribe();
            sObjectConfig.put('recordTypes',JSON.deserializeUntyped(JSON.serializePretty(r.getRecordTypeInfos())));
        }

        if (allowInlineEditing == true){
            List<Object> columnMappings = (List<Object>)sObjectMap.get('_columns');

            for (Integer y = 0; y < columnMappings.size(); y++){
    
                Map<String,Object> columnMap = (Map<String,Object>)columnMappings[y];
                Map<String,Object> fieldMap = (Map<String,Object>)columnMap.get('field');
                String columnName = (String)fieldMap.get('name');
                Boolean fieldEditable = false;

                if (sObjectEditable && isUIAPIEnabled){
                    if (!String.isBlank(columnName) && !columnName.contains('.')){
                        fieldEditable = RelatableUtilities.fieldEditable(childObjectName,columnName); 
                    }
                }
                columnMap.put('editable',fieldEditable);
            }
            sObjectConfig.put('_columns', columnMappings);
        }

        sObjectConfigs.add(sObjectConfig);
    }

    return sObjectConfigs;

}`

Steps To Reproduce:
I ran the following scanner:
sf scanner run dfa -f html -o QA/appexchange/CodeAnalyzerDFA.html -t './' -c 'Security' --projectdir='./'

Desktop:
Provide these details:

Operating System: Mac OS
Code Analyzer version: v3.20.0
Salesforce CLI version: @salesforce/cli/2.23.20 win32-x64 node-v18.19.0
Additional Context:

Workaround:
Tried the directives to exclude from the engine, but it doesn't work
Urgency:
Medium

@johnbelosf johnbelosf added the BUG P3 Rarely Malfunction label Feb 20, 2024
Copy link

git2gus bot commented Feb 20, 2024

This issue has been linked to a new work item: W-15080644

@stephen-carter-at-sf stephen-carter-at-sf added the SFGE Issues related to the Salesforce Graph Engine label May 23, 2024
@stephen-carter-at-sf stephen-carter-at-sf added the duplicate This issue or pull request already exists label Jun 3, 2024
@stephen-carter-at-sf
Copy link
Collaborator

Marking this as a duplicate of #1497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG P3 Rarely Malfunction duplicate This issue or pull request already exists SFGE Issues related to the Salesforce Graph Engine
Projects
None yet
Development

No branches or pull requests

3 participants