Created
May 22, 2017 03:04
-
-
Save az-ak/c6a68235bab20a063ee261227da81577 to your computer and use it in GitHub Desktop.
Find formula fields which use JavaScript in HYPERLINK function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All the standard and custom objects in the Org | |
List<EntityDefinition> entityDefs = [select QualifiedApiName from EntityDefinition]; | |
// Forming a list of Entity API names | |
List<String> entityNames = new List<String>(); | |
for(EntityDefinition entityDef: entityDefs){ | |
if(!entityDef.QualifiedApiName.endsWith('kav')){ | |
entityNames.add(entityDef.QualifiedApiName); | |
} | |
} | |
// Make the describe call | |
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(entityNames); | |
System.debug('Got describe information for ' + results.size() + ' sObjects.'); | |
// Checking if there is a formula field with Javascript used in Hyperlink formula function | |
for(Schema.DescribeSobjectResult res : results) { | |
Map<String, SObjectField> fields = res.fields.getMap(); | |
for(String fieldKey: fields.keySet()){ | |
SObjectField sField = fields.get(fieldKey); | |
Schema.DescribeFieldResult fieldResult = sField.getDescribe(); | |
// This will have the formula string for fields of type Formula | |
String calculatedFormulaString = fieldResult.getCalculatedFormula(); | |
// If formula uses HYPERLINK function, javascript or vbscript or data protocol | |
// cannot be used for security reasons | |
if(null != calculatedFormulaString | |
&& calculatedFormulaString.startsWithIgnoreCase('HYPERLINK') | |
&& (calculatedFormulaString.containsIgnoreCase('javascript:') | |
|| calculatedFormulaString.containsIgnoreCase('vbscript:') | |
|| calculatedFormulaString.containsIgnoreCase('data:')) | |
){ System.debug('Object name: ' + res.getLabel()); | |
System.debug('Field name: ' + fieldKey); | |
System.debug(calculatedFormulaString); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment