Skip to content

Commit

Permalink
Merge pull request apex-enterprise-patterns#462 from apex-enterprise-…
Browse files Browse the repository at this point in the history
…patterns/bugfix/cross-object-person-account-syntax-failure

fixed issue that would not resolve a person account based cross-object syntax
  • Loading branch information
ImJohnMDaniel committed Aug 24, 2023
2 parents 5e325ac + 6fbe369 commit 3e52b94
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions sfdx-source/apex-common/main/classes/fflib_SObjectDescribe.cls
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ public class fflib_SObjectDescribe {
* e.g. getting the Account field on Contact would fail without being referenced as AccountId - both work here.
**/
public Schema.SObjectField getField(String fieldName, Boolean implyNamespace){
Schema.SObjectField result = wrappedFields.get(
(fieldName.endsWithIgnoreCase('__r') ? //resolve custom field cross-object (__r) syntax
(fieldName.removeEndIgnoreCase('__r')+'__c') :
fieldName),
implyNamespace
);
String fieldNameAdjusted = fieldName;

if ( fieldName.endsWithIgnoreCase('__r') ) //resolve custom field cross-object (__r) syntax
{
fieldNameAdjusted = fieldName.removeEndIgnoreCase('__r') + '__c';
}
else if ( fieldName.endsWithIgnoreCase('__pr') ) //resolve custom field cross-object (__pr) syntax for person accounts
{
fieldNameAdjusted = fieldName.removeEndIgnoreCase('__pr') + '__c';
}

Schema.SObjectField result = wrappedFields.get( fieldNameAdjusted, implyNamespace );
if(result == null){
result = wrappedFields.get(fieldName+'Id', implyNamespace); //in case it's a standard lookup in cross-object format
}
Expand Down

0 comments on commit 3e52b94

Please sign in to comment.