1

We've the following post install script in place.

We have recently updated it to check for FLS CRUD validation as Checkmarx scan suggested. Does custom settings need to have this FLS CRUD validation?

global with sharing class ConfigInstaller implements InstallHandler {
global void onInstall(InstallContext context) {
    if(context.previousVersion() == null){
        List<String> configFields = new List<String>{'Name','field__c','field2__c','field3__c','field4__c'};        
        String nameSpace = '';
        List<ApexClass> prefix_Value = [SELECT NamespacePrefix FROM ApexClass WHERE NamespacePrefix='myNameSpace' LIMIT 1];
        if(prefix_Value.size() > 0){
            nameSpace = prefix_Value[0].NamespacePrefix + '__';
            for(integer i = 0; i< configFields.size(); i++){
                if(configFields[i].endsWith('__c')){
                    configFields[i] = nameSpace + configFields[i] ;
                }
            }
        }

        Boolean isAccessible = true;

        // Obtaining the field name/token map for the Config object
        Map<String,Schema.SObjectField> configMap = Schema.SObjectType.PackagedObject__c.fields.getMap();
        for (String fieldToCheck : configFields){
            // Check if the user has create access on the each field
            if (!configMap.get(fieldToCheck).getDescribe().isCreateable()){
                isAccessible = false;
            }
        }

        if(isAccessible){
            PackagedObject__c config = new PackagedObject__c();
            config.Name = '_default';
            config.field__c = '_default';
            config.field2__c = true;
            config.field3__c = true;
            config.field4__c = false;
            insert config; 
        }
    }
}

Now, the installer fails and there is not much information in the error log given.

Salesforce Error Description

Now, am I missing something that is very obvious? What can I do before raising a case with Salesforce?

Thanks in Advance! Peace!

1

Are you sure you need to add the namespace prefix for your custom fields?

As it looks like - you are giving them the namespace prefix but not to the object.

From what I understand - if you are within the context of the package - you do not need to add the namespace prefix, can you try it without, or try to add the prefix to your object name?

Also - adding debug logs and printing them would give you a better way to solve your problem.

Good luck.

  • If the namespace is the case, I should have had issues at other fixes as well right, but the other references(fixes) works fine. I'm planning to mark it false positive since this will execute in a special context and hence doesn't need FLS check. Also, this cannot be invoked anywhere else as well. – Vignesh Aug 11 '16 at 5:50
0

you need to remove with sharing from class , instead of
global with sharing class ConfigInstaller implements InstallHandler { }

use

global without sharing class ConfigInstaller implements InstallHandler { }

or

global  class ConfigInstaller implements InstallHandler { }

Hope it may helps thanks

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.