LoginSignup
0
0

More than 1 year has passed since last update.

ユーザにカスタムオブジェクトの編集を任せる?

Posted at

画面からフィールドの追加ができるみたいです。

Create custom fields with apex

技術的な進化として、Salesforce はtooling API を使用してフィールドを非常に簡単に作成できるようにしました...

String objectapiname = 'Content_Item__c';//replace with your object name
String fieldapiname = 'Country_Name';//replace with your field name
String fieldlabel = 'Country_Name';//replace with your field label
String fielddescription = 'Country Name';//replace with your field label

HttpRequest requestinside = new HttpRequest();
requestinside.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
requestinside.setHeader('Content-Type', 'application/json');
requestinside.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/sobjects/CustomField/');
requestinside.setMethod('POST');
String fieldDef = '{"Metadata" : ';
String metadef = '"type" : "Text","description" : "'+fielddescription+'", "inlineHelpText" : "","precision" : null,"label" : "'+fieldlabel+'","length" : 255,"required" : false'
fieldDef += '{'+metadef+'},';
fieldDef += '"FullName" : "'+objectapiname+'.'+fieldapiname+'__c"}';
system.debug(fieldDef);
requestinside.setBody(fieldDef);
HTTPResponse res = http.send(requestinside);
System.debug(res.getBody());

使用例

MetadataUtility.generateTextField('Account', 'Type_x__c', 'Text Field created by apex', 'Type (apex)');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0