Platform Developer I Certification Maintenance (Winter ’19) Work with the Lightning Map Component and Apex Inherited Sharing

TowerMapUtilClass.apxc

public inherited sharing class TowerMapUtilClass {
public static List queryObjects(String theObject, List theFields, String theFilter, String sortField, String sortOrder) {
String theQuery = ‘SELECT ‘ + string.join(theFields, ‘,’);
theQuery += ‘ FROM ‘ + theObject;
if(!String.isEmpty(theFilter)) {
theQuery += ‘ WHERE ‘ + theFilter;
}
if(!String.isEmpty(sortField)) {
theQuery += ‘ ORDER BY ‘ + sortField;
if(!String.isEmpty(sortOrder)) {
theQuery += ‘ ‘ + sortOrder;
}
}
return database.query(theQuery);
}
}

TowerMapControllerClass.apxc

public inherited sharing class TowerMapControllerClass {
@AuraEnabled
public static List getAllTowers() {
String theObject = ‘Tower__c’;
List theFields = new List{‘Id’, ‘Name’, ‘State__r.Name’, ‘Tower_Location__Latitude__s’, ‘Tower_Location__Longitude__s’};
String theFilter = ”;
String sortField = ‘Name’;
String sortOrder = ‘ASC’;
List allTowers = TowerMapUtilClass.queryObjects(theObject, theFields, theFilter, sortField, sortOrder);
return allTowers;
}
}

Towermap.cmp

3 thoughts on “Platform Developer I Certification Maintenance (Winter ’19) Work with the Lightning Map Component and Apex Inherited Sharing”

  1. I got this error after trying and trying:

    Ensure sharing rules from the calling class are enforced for the the ‘TowerMapUtilClass’ Apex class.

Leave a Reply

Your email address will not be published. Required fields are marked *