-1

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject_describe.htm

I checked the above and try to find out the custom object is linked with any package.

It is getting all custom objects including managed package objects. How can I avoid(filter) managed package objects.

Is there any way to find out the name is not linked with any package ?

salesVision__Key__c - installed package object

1

Its not available that easily and I didn't find anything in describe result.

Salesforce doesn't allow us to add a double underscore to API name, but appends __c at end. Only way for an object to have a double underscore is if from a managed package, because salesforce prepends NameSpace__ to object API name.

By this information, we know that a custom object API with single __ is custom object from org, and with two __'s is from package.

Let the action begin, I have used countMatches string function to identify ic object is from package or not. Apex psuedo code is as follows:

for(Schema.SObjectType fieldDescribe: Schema.getGlobalDescribe().Values()) {
    String apiName = fieldDescribe.getDescribe().getName();
    if(fieldDescribe.getDescribe().isCustom()) {
        if(apiName.countMatches('__') > 1) {
            // its a custom object from package
            System.debug('Packaged object name: ' + apiName);
        } else {
            // its a custom object from package
            System.debug('Non-Packaged/Orgs object name: ' + apiName);
        }
    } else {
        // its a standard object
            System.debug('Standard object name: ' + apiName);
    }
}
-1

I got this regex pattern from forum and figure out the way.

//Code start
Integer objectCount = 0; 
Integer customSettingCount = 0;
//Regex to filter managed package objects
Pattern regEx = Pattern.compile('^\\w*?__\\B\\w*__');
for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
{
    Schema.DescribeSObjectResult objResult = o.getDescribe();
    Matcher filter = regEx.matcher(objResult.getLocalName().toLowerCase());

    if(objResult.isCustom() && filter.find() == false)
    {           
        objectCount++;        
    }
    if(objResult.isCustomSetting() && filter.find() == false)
    {              
        customSettingCount++;           
    }
}
System.debug('Total custom object :'+ objectCount);
System.debug('Total custom Setting :'+ customSettingCount);

//Code End
  • why some one down voted ? explain ? or give better solution ? – bharath Mar 24 '17 at 7:57

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.