0

I have a VF page for my LiveAgent chat application. I am using the below JS code to retrieve UserId of the current user without querying.

try {
     var agentDetails = liveagent.chasitor.getDetails();
     var agentId = agentDetails.agent.userId;
    }

This works great. Now that, I would like to retrieve a specific custom field from the User object, is there a way to get it using the above approach? Like:

var agentField = agentDetails.agent.myField__c;

I am familiar with querying for the field value within Controller and make use of it, but I would like to limit my SOQLs for an efficient implementation.

0

Making some assumptions about the details when answering this but a Visualforce page will have access to the record using getRecord().

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_getRecord.htm

Now if I am hearing you wrong, the answer is you cannot per the linked documentation above.

Per documentation: Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression.

Here's an example if your controller is right on the record itself, the simple example.

String agentRecordCustomField = (string)agentRecord.get('myField__c');

System.debug(agentRecordCustomField);

Here's an example for an Account controller:

Account acct = (Account)controller.getrecord();
String acctCustomField = (string)acct.get('Custom_Field__c');

System.debug(acctCustomField);

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.