function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kasper Kristensen 3Kasper Kristensen 3 

Populating design picklist with fields based on object id

Hi.

I have a lightning component, with a design file that includes a two picklists. These picklists are currently being populated by referencing a class that extends "VisualEditor.DynamicPickList", using the datasource attribute on the design:attribute control. Like this : datasource="apex://ClassName.

This works fine, but i am getting all the fields specifically from the Account object right now, like this:
"Map<String, Schema.SObjectField> fldObjMap = schema.SObjectType.Account.fields.getMap();" and using that to populate the picklist.

What i would like to do, is to populate the picklist with all fields, based on what object the user is inserting the lightning component on. If the user inserts the lightning component on a Contact, it should list all Contact fields. If it is inserted on a Campaign object, it should list all the Campaign fields etc.

I am kinda stuck at how to to this.

I am supposed to be able to get the recordId, from the URL i guess. When i go into "Edit page" (where this should be used), i have a querystring in the URL called "pageId". And i should be able to get that through apex code. Something like this "ApexPages.CurrentPage().getparameters().get('id');".

But i can't get this to work. And i guess this has something to do with, that i am trying to do this in the "VisualEditor.DynamicPickList" extending class. But if someone could point me in the right direction, it would be awesome.

I just want to get the current object type in this extending class, that populates the picklists with field values. Simple as that. 
Kasper Kristensen 3Kasper Kristensen 3
Does no one have any ideas? Or am i trying to accomplish something impossible? :-/
IT Administrator 54IT Administrator 54
Were you able to get this working?
I would also like to pass a parameter to my VisualEditor.DynamicPickList class or at least get the current object type.
Using url parameters similar to visualforce does not work, "apex://ClassName?id=yourId". (class does not exist error)
If this is indeed not possible we need to spin up an idea for SF!
Kasper Kristensen 3Kasper Kristensen 3
Unfortunately, no i did not find any way to do this. I ended up creating specific components for each object.