Skip to content

Commit

Permalink
Fixed code that got the Selector type for a given Sobject Type
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Apr 21, 2022
1 parent 20d029e commit 9534a6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public inherited sharing class ortoo_SelectorFactory extends fflib_Application.S
Map<String,String> selectorNameBySobjectName = new Map<String,String>();

/**
* Constructor, allowing the definition of the Sobject to Domain Type mappings
* Constructor, allowing the definition of the Sobject to Domain Type mappings based on their names
*
* @param Map<SObjectType,Type> The mapping of Sobject to Domain Type
* @param Map<String,String> The mapping of Sobject Name to Domain Type Name
*/
public ortoo_SelectorFactory( Map<String,String> selectorNameBySobjectName )
{
Expand All @@ -38,7 +38,7 @@ public inherited sharing class ortoo_SelectorFactory extends fflib_Application.S
}
catch ( fflib_Application.DeveloperException e )
{
String sobjectTypeName = sObjectType.getDescribe().getLocalName();
String sobjectTypeName = SobjectUtils.getSobjectLocalName( sobjectType );
// if the base factory didn't manage to get a type, then try to build a new one from *our* config
String selectorClassName = selectorNameBySobjectName.get( sobjectTypeName );

Expand Down Expand Up @@ -71,7 +71,7 @@ public inherited sharing class ortoo_SelectorFactory extends fflib_Application.S
{
Contract.requires( sobjectType != null, 'getSelectorType called with a null sobjectType' );

String typeName = selectorNameBySobjectName.get( SobjectUtils.getSobjectName( sObjectType ) );
String typeName = selectorNameBySobjectName.get( SobjectUtils.getSobjectLocalName( sObjectType ) );
if ( typeName == null )
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private without sharing class ortoo_SelectorFactoryTest
{
ortoo_SelectorFactory factory = new ortoo_SelectorFactory( new Map<String,String>
{
PackageUtils.NAMESPACE_PREFIX + '__Application_Configuration__mdt' => 'ortoo_SelectorFactoryTest.RegisterableType'
'Application_Configuration__mdt' => 'ortoo_SelectorFactoryTest.RegisterableType'
});

Test.startTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public inherited sharing class SobjectUtils
return sobjectName;
}

/**
* Given an SObjectType, will return the Local version of the developer / API name of the SObject (e.g. Contact)
*
* @param SobjectType The SObjectType to return the Name for
* @return String The Local API Name of the SObjectType
*/
public static String getSobjectLocalName( SobjectType sobjectType )
{
Contract.requires( sobjectType != null, 'Attempted to get the local name of a null SObjectType' );

String sobjectName = sobjectType.getDescribe().getLocalName();

Contract.ensures( sobjectName != null, 'getSobjectLocalName returned with a null sobjectName' );
return sobjectName;
}

/**
* States if the given SObject is of a type that the current user is allowed to insert
*
Expand Down

0 comments on commit 9534a6f

Please sign in to comment.