I have a requirement to display opportunity records on Google Maps. Here is my LWC Code on Opportunity. I'm unable to retrieve address from Account object: import { LightningElement, api,wire } from 'lwc'; import getOpportunityList from '@salesforce/apex/
Using the Salesforce API, this code will first retrieve a list of opportunities getOpportunityList Apex method. It will then map each opportunity to a Google Maps marker. The opportunity name and description will be shown beside the markers.
Here are some further details regarding this code:
The getOpportunityList Apex method is a custom Apex method that you will need to create.
The @api annotation is used to expose the opportunities property to the Lightning UI.
The @wire annotation is used to wire the getOpportunityList service to the opportunities property.
The render() method is used to render the Google Maps.
import getOpportunityList from '@salesforce/apex/OpportunityMap.getOpportunityList';
export default class OpportunityOnMap extends LightningElement {
@api opportunityIdS;
mapMarkers = [];
connectedCallback(){
console.log('++++ opportunityIdS : ' + this.opportunityIdS);
if(this.opportunityIdS){
getOpportunityList({ opportunityIdS: this.opportunityIdS }).then(result=> {
console.log('@@@@ result '+result);
result.forEach(dataItem => {
this.mapMarkers = [...this.mapMarkers,
{
location: {
City: dataItem.BillingCity,
Country: dataItem.BillingCountry,
PostalCode: dataItem.BillingPostalCode,
State: dataItem.BillingState,
Street: dataItem.BillingStreet,
Type: dataItem.Type,
Name : dataItem.Name,
},
icon: 'standard:opportunity',
title : dataItem.Name,
}
];
});
}).catch(error => {
console.log('error#'+error);
})
}
}
}
Using the Salesforce API, this code will first retrieve a list of opportunities getOpportunityList Apex method. It will then map each opportunity to a Google Maps marker. The opportunity name and description will be shown beside the markers.
Here are some further details regarding this code:
- The getOpportunityList Apex method is a custom Apex method that you will need to create.
- The @api annotation is used to expose the opportunities property to the Lightning UI.
- The @wire annotation is used to wire the getOpportunityList service to the opportunities property.
- The render() method is used to render the Google Maps.
I hope this helps!