Friday, January 11, 2019

Platform Developer I Certification Maintenance (Winter '19) Code

After Creating the Tower object in the developer org add the four records mentioned in the trailhead challenge and copy the below code blocks to finish the challenge.

  • Copy the helper class code block, TowerMapUtilClass, from above and modify it so the sharing rules are enforced based on the sharing setting of the calling class.

    • TowerMapUtilClass
    •  public inherited sharing class TowerMapUtilClass {  
          public static List<sObject> queryObjects(String theObject, List<String> 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);  
          }  
       }  
      
  • Copy the controller code block, TowerMapControllerClass, from above and modify it so the sharing rules are enforced.

    • TowerMapControllerClass
    •  public inherited sharing class TowerMapControllerClass {  
          @AuraEnabled  
          public static List<Tower__c> getAllTowers() {  
            String theObject = 'Tower__c';  
            List<String> theFields = new List<String>{'Id', 'Name', 'State__r.Name', 'Tower_Location__Latitude__s', 'Tower_Location__Longitude__s'};  
            String theFilter = '';  
            String sortField = 'Name';  
            String sortOrder = 'ASC';  
            List<Tower__c> allTowers = TowerMapUtilClass.queryObjects(theObject, theFields, theFilter, sortField, sortOrder);  
            return allTowers;  
          }  
       }  
      
  • Copy and modify the Lightning component code above to implement a lightning:map component named Towermap. Replace the  with your code. Your code should pass the value of v.mapMarkers to the mapMarkers attribute, pass the value of v.markersTitle to the markersTitleattribute, and set the zoomLevel attribute to 5.

    • Towermap.cmp
    •  <aura:component implements="flexipage:availableForAllPageTypes" controller="TowerMapControllerClass" access="global" >  
          <aura:attribute name="mapMarkers" type="Object" access="PRIVATE" />  
          <aura:attribute name="markersTitle" type="String" access="PRIVATE" />  
          <aura:handler name="init" value="{!this}" action="{!c.handleInit}"/>  
          <aura:if isTrue="{!!empty(v.mapMarkers)}" >  
            <!-- Create lightning:map here -->  
            <lightning:map   
           mapMarkers="{! v.mapMarkers }"   
           zoomLevel="{!v.zoomLevel}" markersTitle="{!v.markersTitle}"/>  
          </aura:if>  
       </aura:component>  
      
  • Copy and paste the controller and helper code blocks above to create controller and helper functions to pull all Tower locations from the server.

    • TowermapController.js
    •  ({  
          handleInit: function (component, event, helper) {  
            helper.initHelper(component, event, helper);  
            component.set('v.zoomLevel', 5);  
          }  
       })  
      
    • TowermapHelper.js
    •  ({  
          initHelper : function(component, event, helper) {  
            helper.utilSetMarkers(component, event, helper);  
          },  
          utilSetMarkers : function(component, event, helper) {  
            let action = component.get("c.getAllTowers");  
            action.setCallback(this, function(response) {  
               const data = response.getReturnValue();  
               const dataSize = data.length;  
               let markers = [];  
               for(let i=0; i < dataSize; i += 1) {  
                 const Tower = data[i];  
                 markers.push({  
                   'location': {  
                      'Latitude' : Tower.Tower_Location__Latitude__s,  
                      'Longitude' : Tower.Tower_Location__Longitude__s  
                   },  
                   'icon': 'utility:Tower',  
                   'title' : Tower.Name,  
                   'description' : Tower.Name + ' Tower Location at ' + Tower.State__r.Name  
                 });  
               }  
               component.set('v.markersTitle', 'Out and About Communications Tower Locations');  
               component.set('v.mapMarkers', markers);  
            });  
            $A.enqueueAction(action);  
          }  
       })  
      
  • To view your map, you can use Lightning App Builder to create a standalone one-column app page named Towers and add it to the Lightning Experience App Launcher. More experienced developers can chose another method to expose the component, if desired.
    • Setup ➤ Lightning App Builder ➤  Click "New" ➤  Select App Page ➤ Click Next ➤ Give Label as "Towers" ➤  Select "One Column" ➤  Select "Towermap" under the lightning components section and add the component to the lightning page
    • Save and activate the lightning page to display the page in the sales,service applications.
I Hope useful for You! Feel Free Comment Below Your Experience in this Page!!

5 comments:

  1. Hi Saravanan, Any suggestions on this message? "Ensure sharing rules are enforced for the 'TowerMapController' Apex class."

    ReplyDelete
  2. are you replace the TowerMapController class code?

    ReplyDelete
  3. Prepare4Test Adobe 9A0-411 PDF is designed with the latest 9A0-411 exam material. All questions are planned and verified by Adobe certified experts.

    ReplyDelete