added based on comments
It seems there is a bug for importing geolocation fields (able to import other compound fields like BillingCity). So, we can use direct string notation as below.
Geolocation
type fields are Compound Fields (like BillingAddress
). Two main points to be highlighted from docs is :
Geolocation is a compound field that counts toward your org’s limits
as three custom fields: one for latitude, one for longitude, and one
for internal use. Support for the compound field (geolocation) versus
the field’s components (latitude and longitude) varies depending on
the functionality you’re using in Salesforce. For example, you can
create list views that show the field and its components, but you
can’t select the compound geolocation field in Apex. You can run SOQL
queries only on a geolocation field’s components.
Compound fields are accessible only through the SOAP and REST APIs.
The compound versions of fields aren’t accessible anywhere in the
Salesforce user interface.
Below is the working sample code:
import { LightningElement, wire, api, track } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
export default class Poc extends LightningElement {
@api recordId;
@wire(getRecord, {
recordId: '$recordId',
fields: [ 'Account.Acc_Location__Latitude__s', 'Account.Acc_Location__Longitude__s' ]
})
wiredAcc({ data, error }) {
console.log('Account => ', JSON.stringify(data), JSON.stringify(error));
}
}
and its output:
{
"apiName": "Account",
"childRelationships": {
},
"fields": {
"Acc_Location__Latitude__s": {
"displayValue": null,
"value": 1.2345678
},
"Acc_Location__Longitude__s": {
"displayValue": null,
"value": 2.3456789
}
},
"id": "00128000009j45sAAA",
"lastModifiedById": "00528000001IIBvAAO",
"lastModifiedDate": "2019-08-25T14:37:49.000Z",
"recordTypeInfo": null,
"systemModstamp": "2019-08-25T14:37:49.000Z"
}
Note that you should ideally use imported fields instead of direct strings in parameter
I am wondering if this is a timing issue, where you are calling testMe before the getRecord is finished, though I'd need to see your template to be sure.
But I re-created your code in a scratch org, and it worked ok when I used this as my template, but without the if:true, both Name and Service Area are undefined
<template>
<template if:true={app}>
Test Me: {testMe}
</template>
</template>
And my controller:
import { LightningElement, api, track, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import APP_NAME from '@salesforce/schema/Application__c.Name';
import APP_SERVICEAREA from '@salesforce/schema/Application__c.Service_Area__c';
export default class StackAppRecord extends LightningElement {
@api recordId; // Application__c.Id
@track app; // Application__c record
@track appName;
// ...
@wire(getRecord, { recordId: '$recordId', fields: [APP_NAME,APP_SERVICEAREA] })
loadRecord ({ error, data }) {
if (data) {
this.app = data;
this.error = undefined;
console.log('got data');
} else if (error) {
// ...
}
}
// Called from a {testMe} in the HTML template
get testMe() {
console.log(this.app); // returns a Proxy
console.log(JSON.stringify(this.app)); // returns a JSON as expected:
console.log(this.app.fields.Name.value); // shows Name Value:
console.log(this.app.fields.Service_Area__c.value); // show Service Value:
return '?!';
}
}
Best Answer
you have to use
getFieldValue
in order to get parent field valuestake a look at the getFieldValue documentation. Here is a good example to follow.