How to get custom object id dynamically. I have created one button on UI called Create custom field and on click of that button, I want to redirect it to that custom object field creation page(object manager->field and relationships-> new). I cannot give hardcoded id to that link and also it's not taking API name. for API name its showing insufficient privileges. Is it possible using tooling API? and How?
-
Where you will use the button?– sanket kumarJul 23, 2019 at 12:39
-
In the lightning web component. for App exchange app.– akashg7Jul 23, 2019 at 13:00
-
And the Lightning component will be used On record page or home page or App Page?– sanket kumarJul 23, 2019 at 13:02
-
Lightning web component will be used on the app page!– akashg7Jul 23, 2019 at 13:03
-
I think '/lightning/setup/ObjectManager/Object_Api_Name/FieldsAndRelationships/new' will work if you pass the object api name dynamically.– sanket kumarJul 23, 2019 at 13:05
3 Answers
you may try to use the following SOQL Query to get the Id:
Id myCustomObjectId = [SELECT CustomObjectId FROM CustomObjectUserLicenseMetrics WHERE CustomObjectName ='MyCustomObjectName' limit 1].id;
hope it helps
yes instead of getting the id of the object and redirecting the page to create a custom field, you can create a field using Tooling api itself. I have written a lightning component to create custom object fields for any object (Whichever is accessible to create custom fields). Let me know if you need the code.
-
I have done that too but the requirement is to only give button which will redirect to that page.– akashg7Jul 24, 2019 at 5:40
Just got to know we can query like this. Got the result using this-
SELECT DurableId FROM EntityDefinition WHERE QualifiedApiName = 'CustomObject__c'