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
Tyler ZikaTyler Zika 

Format a remote object to display proper data

Hello, 

I'm accessing Salesforce record data with remote javascript.

This tutorial introduces doing this.

https://developer.salesforce.com/trailhead/en/lightning_design_system/lightning-design-system4

Have a custom fields: due date, complete date, completed by, and assigned to.

When I access these fields with remote objects, they return in a format I don't want displayed.

For example, due date returns: Sat Jan 25 2014 00:00:00 GMT-0800 (PST). I want it to display 01/25/2014
Assigned To return the user id: 005d0000000xlRkAAI. I want it ti display the users first and last name.

How do I do this? This is pure JavaScript, so do I use JavaScript or is there a way to embed Apex in my JS script?
Best Answer chosen by Tyler Zika
Bryan JamesBryan James
Hi Tyler got some good and bad news. So some good news first: to format the date fields to be more user readable its as simple as "record.get('DueDate').toLocaleDateString()"
The bad new, as of yet it seems you still cannot use relational fields in remote objects. That being said I did find an interim solution on salesforce stack exchange presented by Mohith Shrivastava. His idea is to create a formula field on the Account object that retrieves the fields you are looking for and then query for the formula field in the remote object. "CreatedBy.FirstName + ' ' +CreatedBy.LastName".

Hope this helps.

All Answers

Bryan JamesBryan James
Hi Tyler got some good and bad news. So some good news first: to format the date fields to be more user readable its as simple as "record.get('DueDate').toLocaleDateString()"
The bad new, as of yet it seems you still cannot use relational fields in remote objects. That being said I did find an interim solution on salesforce stack exchange presented by Mohith Shrivastava. His idea is to create a formula field on the Account object that retrieves the fields you are looking for and then query for the formula field in the remote object. "CreatedBy.FirstName + ' ' +CreatedBy.LastName".

Hope this helps.
This was selected as the best answer
Tyler ZikaTyler Zika
Thanks Bryan! What are those functions called that change the data looks? The .toLocaleDateString()?
Bryan JamesBryan James
Hi Tyler, that method is part of the JavaScript Date Objects. You can look at all the different Javascript date functions here. http://www.w3schools.com/jsref/jsref_obj_date.asp I'm glad I could be of some help. Good Luck!