Skip to main content

I am currently encountering a similar challenge. I am building a custom Lightning Web Component (LWC) to replicate standard Salesforce List View functionality, which will allow users without administrative access to create and manage their own list views. I am utilizing Named Credentials to handle the creation and updating of these list views.

However, I am running into a few issues:

First, I am unable to retrieve only the fields that are eligible for List View creation. When I fetch the fields for the User object, the system returns every field on the object. I have realized that not all of these fields are actually available or supported for use inside a standard List View.

Second, when attempting to save the list view via the Metadata API, the standard SOQL field API names fail. When I fetch an existing list view to inspect it, the XML returns completely different internal API names, as shown in the snippet below: 

<ListView xmlns="

http://soap.sforce.com/2006/04/metadata

"> 

    <fullName>testing_list_view_2</fullName> 

    <columns>CORE.USERS.FAX</columns> 

    <columns>CORE.USERS.FIRST_NAME</columns> 

    <columns>FULL_NAME</columns> 

    <columns>DVC_Is_Manually_Cleared__c</columns> 

    <columns>CORE.USERS.LAST_LOGIN</columns> 

    <columns>CORE.USERS.LAST_NAME</columns> 

    <columns>CORE.USERS.MIDDLE_NAME</columns> 

    <columns>CORE.USERS.CELL</columns> 

    <columns>CORE.USERS.COMMUNITY_NICKNAME</columns> 

    <columns>OOO_End_Date__c</columns> 

    <columns>OOO_Start_Date_Time__c</columns> 

    <columns>CORE.USERS.PHONE</columns> 

    <columns>Planned_Activation_Date__c</columns> 

    <columns>CORE.USERS.STATE_CODE</columns> 

    <columns>CORE.USERS.SUFFIX</columns> 

    <filterScope>Everything</filterScope> 

    <label>testing list view 2</label> 

    <sharedTo> 

        <allInternalUsers></allInternalUsers> 

    </sharedTo> 

</ListView> 

 

Based on this, I have two questions:

  1. Is there a programmatic way to retrieve only the specific fields that are available for selection when creating a User List View in the standard Salesforce UI?
  2. Is there an official documentation page or mapping matrix I can refer to that translates standard SOQL field API names to these specific Metadata API names?

#Salesforce Developer  #TrailblazerCommunity  #Apex

1 réponse
  1. 25 oct., 22:12

    Hi Manav, there's no published mapping for those CORE.USERS.* tokens, but you can get both pieces from the platform instead of hard-coding them: 

    1) Eligible columns: call the REST List Views describe endpoint on an existing User list view (/sobjects/User/listviews/{listViewId}/describe). Each column comes back with fieldNameOrPath (the normal field API name) and selectListItem, and the sortable/filterable flags tell you what the UI allows. 

    2) Token mapping: as a one-time step, create a User list view in the UI with every column you want to support, retrieve it with the Metadata API, and compare its <columns> with the describe output. Store that as a small mapping (custom metadata works well). Custom fields like DVC_Is_Manually_Cleared__c keep their normal API name, so only standard fields need mapping. 

    3) For filters, use Schema describe (DescribeFieldResult.isFilterable()) to remove fields that can't be filtered before showing them in your LWC. 

    Also, since you're using a Named Credential for Metadata API calls, check that the integration user's permissions don't let end users create list views beyond what you intend. Hope this helps!

0/9000