0

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 kumar Jul 23 at 12:39
  • In the lightning web component. for App exchange app. – akashg7 Jul 23 at 13:00
  • And the Lightning component will be used On record page or home page or App Page? – sanket kumar Jul 23 at 13:02
  • Lightning web component will be used on the app page! – akashg7 Jul 23 at 13:03
  • I think '/lightning/setup/ObjectManager/Object_Api_Name/FieldsAndRelationships/new' will work if you pass the object api name dynamically. – sanket kumar Jul 23 at 13:05
1

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

  • It's not working! – akashg7 Jul 24 at 5:50
0

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. – akashg7 Jul 24 at 5:40
0

Just got to know we can query like this. Got the result using this-

SELECT DurableId FROM EntityDefinition WHERE QualifiedApiName = 'CustomObject__c'

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.