0

I am using describe call and getting all the fields of a specific object.

I dont want the system defined fields like (Id, LastModifiedBy, etc) in the final list which i will obtain through the describe call. I tried using isCreateable() & isUpdateable() of Schema.DescribeFieldResult class but got no success.

One way to do this is by removing the fields which i dont want from the list. But i want a dynamic way to do this.

Can anybody help me identify system and audit fields from list of fields using dynamic apex?

2 Answers 2

1

From DescribeFieldResult Class:

isCustom()

Returns true if the field is a custom field, false if it is a standard field, such as Name.

0

I needed to do the same thing and unfortunately there's not an easy (and dynamic) way to do this as far as I know, so I ended up creating a set of blacklisted system fields that I know I didn't want and if the field API name showed up in the list when I was gathering fields via the Schema class I just ignored it. My final list ended up being:

private Set<String> blacklistedFields = new Set<String>{'CompletedDateTime','RecurrenceRegeneratedType','RecurrenceMonthOfYear','RecurrenceInstance','RecurrenceDayOfMonth','RecurrenceDayOfWeekMask','RecurrenceType','RecurrenceTimeZoneSidKey','RecurrenceEndDateOnly','RecurrenceStartDateOnly  ','RecurrenceActivityId','ReminderDateTime','ActivityOriginType','ArchivedDate','IsArchived','IsClosed','PrioritySortOrder','IsHighPriority','AccountId','Jigsaw Contact Id','ReportsToName','EmailBouncedReason','EmailBouncedDate','IsEmailBounced','JigsawContactId','Id','IsDeleted','CreatedDate','LastModifiedDate','SystemModstamp','LastActivityDate','LastViewedDate','LastReferencedDate','UserRecordAccessId','MasterRecordId','AccountSource','IsCssEnabled','CssLastLoginDate','CompareName','PhotoUrl','CompareSite','OwnerAlias','JigSawCompanyId','ConnectionReceivedDate','ConnectionSentDate','AccountRollupId','ProductIsArchived'};     

Very long, I know! It would really be nice if Salesforce had an easy way to get only fields that show up in the Object Manager.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .