2

I am working on dumping the Salesforce custom object to a database. I wanted to know if there is any way at the API level to determine if the field was renamed.

Implementation wise, I get the Salesforce field definitions and store them locally. This would be compared against the live field definitions to detect a change. For example, if an object has fields [F1, F2, F3] and F3 had been renamed to F4, the field definitions retrieved are [F1, F2, F4]. It might be easier to deduce that F3 had been renamed to F4 if (field name, field labels) are changed. There's a catch to this approach. If the field definitions of F2 and F3 are the same, provided the field definitions retrieved were [F1], there isn't a way to deduce which field was renamed to F4.

Is there a way to retrieve any info from Standard objects or field definitions that identifies a field rename?

2

The easiest way to track changes would be to use the field's ID, which never changes, even if the field is renamed or deleted and subsequently recovered before the recycle bin removes it permanently. To get at this data, use the Tooling API to query the fields:

SELECT Id, DeveloperName, NamespacePrefix, TableEnumOrId FROM CustomField

Of course, you'll have to have queried this data beforehand and cached it somewhere to determine if it's the same field or not.

The SetupAuditTrail object also tracks this information, but requires parsing a field that describes the change, which would look like "Changed field name of OldFieldName custom field on ObjectName from OldFieldName to NewFieldName."

  • As you'd said, this would require prefetching of the data for the field definition. Also noticed that CustomField definitions once modified are immediately removed, i.e, not undeleteable from the recycle bin. I also gave a shot with the second method for parsing that requires obtaining the field label instead of the field's name. – dmachop Oct 26 '18 at 19:49
  • It is of the format "Changed field name of <NewFieldLabel> custom field on <ObjectLabelInPlural> from <OldFieldName> to <NewFieldName>". Note that the oldfieldname and newfieldname will not have __c suffixes. I don't know why even bother to do this in such a case as it could have been easily with label to maintain consistency. – dmachop Dec 4 '18 at 20:55
  • @dmachop Yeah, I think that's odd that it uses the label rather than the name, especially in orgs where admins get sneaky and label several fields by the same name for record type separation or page layouts or whatever. – sfdcfox Dec 4 '18 at 20:59

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.