What I'm trying to do is list out all objects and then go through each field per object to see if that field contains a certain value fieldName.contains('aov')
. (AKA trying to see where my field resides on which objects)
When I try to build out my results
I keep getting an exception:
System.InvalidParameterValueException: Invalid sobject provided. The Schema.describeSObject() methods does not support the Getting_Started__kav sobject as a parameter. If you are attempting to use a Knowledge Article Type, be sure to use the abstract KnowledgeArticleVersion instead.
If someone could help me loop through to skip the object that is throwing the error that would be great!! Currently I'm running my APEX, waiting for the exception to be thrown, then adding that object to my list to skip. There has to be a better way but I'm too new to know. Here's my script, any advice or suggestions would be awesome.
String[] objectNames = new String[]{};
for ( Schema.SObjectType typ : Schema.getGlobalDescribe().values() ) {
String sobjName = String.valueOf(typ);
if ( !sobjName.contains('Knowledge_Article__kav') &&
!sobjName.contains('Documentation__kav') &&
!sobjName.contains('Internal_Procedures__kav') &&
!sobjName.contains('Quick_Starts__kav') ) {
objectNames.add(sobjName);
//System.debug(sobjName);
}
}
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objectNames);
for (Schema.DescribeSObjectResult res : results){
//System.debug(res.getLabel());
for(String fieldName : res.fields.getMap().keySet()){
if (fieldName.contains('aov') || fieldName.contains('AOV')) {
System.debug(res.getLabel() + ' -- ' + fieldName);
}
}
}
A second question to follow up on this (not sure if I should create a 2nd post or not), is this script to labor intensive and is there a cleaner way to write it? Will I run into any limit issues with this?