{{{$User.userId}}} displays Salesforce Id instead of name

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I've had this problem before and have worked around it in some cases. When auto-populating a reference field in edit mode through an action, the field populates with the Salesforce ID instead of the reference record's name. In my current use, I want to have a task that can be assigned to other users as owner. It works as planned except that I want the owner field to prepopulate upon page load with the userId of the current user. They can then change that to another user if they want to assign the task to others. The problem is that when the field populates, it populates with the Salesforce user ID instead of the userID. I tried triple Mustache, global merge variable for user and creating a model on the user object and pulling the userId from there. All have the same result: Salesforce Id instead of UserId. It does work, but it looks sloppy to the user having a jumble of numbers and letters in the userId field.
Anyone have any suggestions?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
This worked for me:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Task">   <models>
      <model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" adapter="" type="" sobject="User" doclone="">
         <fields>
            <field id="Id"/>
            <field id="Name"/>
            <field id="FirstName"/>
            <field id="LastName"/>
         </fields>
         <conditions>
            <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
         </conditions>
         <actions/>
      </model>
      <model id="Task" limit="1" query="false" createrowifnonefound="true" sobject="Task" adapter="" type="">
         <fields>
            <field id="Subject"/>
            <field id="OwnerId"/>
            <field id="Owner.Name"/>
            <field id="Owner.Username"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="OwnerId" operator="=" userinfotype="userid" model="CurrentUser" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <pagetitle model="Task" uniqueid="sk-3gp5r3-71">
         <maintitle>
            <template>New {{Model.label}}</template>
         </maintitle>
         <subtitle>
            <template>{{Model.labelPlural}}</template>
         </subtitle>
         <actions>
            <action type="savecancel" afterCancel="/{{Model.KeyPrefix}}/o" afterSave="/{{Id}}" rollbackonanyerror="true"/>
         </actions>
      </pagetitle>
      <basicfieldeditor showsavecancel="false" showheader="true" model="Task" mode="edit" uniqueid="sk-3gp5r3-72" buttonposition="">
         <columns>
            <column width="50%">
               <sections>
                  <section title="Basics">
                     <fields>
                        <field id="Subject"/>
                     </fields>
                  </section>
               </sections>
            </column>
            <column width="50%">
               <sections>
                  <section title="Additional Info">
                     <fields>
                        <field id="OwnerId" valuehalign="" type="" optionsource="" displaytemplate="">
                           <searchfields/>
                           <filters/>
                           <renderconditions logictype="and" onhidedatabehavior="keep"/>
                           <enableconditions/>
                        </field>
                     </fields>
                  </section>
               </sections>
            </column>
         </columns>
      </basicfieldeditor>
   </components>
   <resources>
      <labels/>
      <css/>
      <javascript/>
   </resources>
   <styles>
      <styleitem type="background" bgtype="none"/>
   </styles>
</skuidpage>
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Thanks Irvin, but I still get Salesforce Id displaying. Anyone know any model confilcts or settings that may cause this? I have 25 models on this page, so there is plenty of room for conflict.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Raymond.  This trips lots of people up. 

You are creating new records and want to prepopulate a reference field.  You pass the ID in,  either as a condition or as a prepopulation (in the create new row action) or as a subsequent field update action. What do you find:  Just the ID.... Boo... We all want the name! 

The problem here is that we don't have a real salesforce record yet,  we don't automatically run a queries on the user object to retrieve the name that matches that ID.  Without the data in the model, all we've got is the name! 

The solution here is add a second line to your pre-population where you force the name into the parent object.  See below how I've done it for tasks. 




Then the name value is in the model and can be displayed. 

Can't show what you don't have.....
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Ha! Glad I asked. Works like a charm. Thanks!