1

Is there any way to create bulk fields in salesforce. For example. If i want to have 10 custom text fields, i want a interface by which i create 10 custom text fields for an object with a different name at a single shot.

1 Answer 1

3

Adding fields dynamically may not be a good design unless its really required.

Salesforce Metadata API is a way out to create fields dynamically. This API can be called from different language app as well. And make sure to have System Admin role before running this code.

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'CustomObject__c.CustomField__c';
customField.label = 'Custom Field';
customField.type_x = 'Text';
customField.length = 10;
MetadataService.AsyncResult[] results =
    service.create(new List<MetadataService.Metadata> { customField });

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.