0

I am looking for a way to create custom field from Apex.

Use case: we are using a specific field (E.g.: Own_Id_Field__c, TEXT(255), ExternalID: TRUE).

User should be able to select which (Custom) Object they want to use in the app and this should create custom field (for good functioning).

I would like to do someting like:

public static Schema.DescribeFieldResult createOwnIdField(String sObject) {
  // Test if sObject exists
  // Create field
  return field;
}

I heard about using Metadata API but did not really understood.

2
  • @RahulSharma Thanks. I would like confirmation of compatibility with 41
    – Simonp
    Jan 26 '18 at 12:09
  • Its relatively easy, what's stopping you to try and confirm it? The Metadata API wrapper by Andrew Fawcett really works well, there should be no reason for it to break in version 41, that is being used by a lot of ISV's as well.
    – Raul
    Jan 26 '18 at 12:59