0

I have written below query in Javascript(Visualforce page) and trying to access query result as shown below, but it is failing at second console log and giving error in developer console.

var user_query = "Select Id, contact.account.Name From User WHERE Id='" + user.userId + "' LIMIT 1";
var userQuery = sforce.connection.query(user_query);
var usrResult = userQuery.getArray('records')[0];
console.log('Working1***'+usrResult);
console.log('Working2***'+usrResult.contact.account.Name);

And below is the output from developer console.

Working1***{type:'User', Id:'00550000002pvqOAAQ', Contact:{type:'Contact', Id:null, Account:{type:'Account', Id:null, Name:'RUCKUS TEST VAR1', }, }, }
SCRIPT5007: Unable to get property 'account' of undefined or null reference

Is there something I am missing while rendering Account name

1 Answer 1

0

Javascript is case sensitive. A property "Contact" is not the same as property "contact". Access your property with

console.log('Working2***'+usrResult.Contact.Account.Name);

Your first console output gives you the correct cases for the properties.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.