Salesforce Developer Interview Questions

1. Difference between queueable and batch apex?  Batchable Apex: If it is a long-running complex process then you should go for Batchable Apex and you can have an option to schedule the batch to run at a customized time. It can process up to 50 million records in asynchronous mode. 5 concurrent jobs are allowed to run at a time and future methods are not allowed in the Batch class. Batch Class should implement Database. Batchable interface and it should have three methods start(), execute() and finish() methods. Queueable Apex: It comes in handy when you need to have both the operations of Batch and future method and it should implement Queueable Interface. If one job is dependent on another job means here we can chain the dependent job in execute method by system.enqueuejob(new secondJob()); You can also able to chain up to 50 jobs and in the developer edition, you can able to chain up to 5 jobs only. It will accept non-primitive types like sObjects and it also runs in asynchronous mo

Lightning Web Components Specialist Superbadge Solution Boat Map Component

 BOAT MAP COMPONENT


boatMap.html


<template>

  <lightning-card title="Current Boat Location" icon-name="action:map">

    <template if:true={showMap}>

      <lightning-map map-markers={mapMarkers} zoom-level="10"></lightning-map>

    </template>

    <template if:false={showMap}>

      <span class="slds-align_absolute-center">

        Please select a boat to see its location!

      </span>

    </template>

  </lightning-card>

</template>


boatMap.js


import { LightningElement, api, wire } from 'lwc';

import { getRecord } from 'lightning/uiRecordApi';

// import BOATMC from the message channel

import { APPLICATION_SCOPE, MessageContext, subscribe, unsubscribe } from 'lightning/messageService';

import BOATMC from '@salesforce/messageChannel/BoatMessageChannel__c';

// Declare the const LONGITUDE_FIELD for the boat's Longitude__s

// Declare the const LATITUDE_FIELD for the boat's Latitude

// Declare the const BOAT_FIELDS as a list of [LONGITUDE_FIELD, LATITUDE_FIELD];

const LONGITUDE_FIELD = 'Boat__c.Geolocation__Longitude__s';

const LATITUDE_FIELD = 'Boat__c.Geolocation__Latitude__s';

const BOAT_FIELDS = [LONGITUDE_FIELD, LATITUDE_FIELD];


export default class BoatMap extends LightningElement {

  // private

  subscription = null;

  @api boatId;


  // Getter and Setter to allow for logic to run on recordId change

  // this getter must be public

  @api

  get recordId() {

    return this.boatId;

  }

  set recordId(value) {

    this.setAttribute('boatId', value);

    this.boatId = value;

  }


  error = undefined;

  mapMarkers = [];

  

  // Initialize messageContext for Message Service

  @wire(MessageContext)

  messageContext;

  // Getting record's location to construct map markers using recordId

  // Wire the getRecord method using ('$boatId')

  @wire(getRecord, {

  recordId: this.boatId,

  fields: BOAT_FIELDS})  

  wiredRecord({ error, data }) {

    // Error handling

    if (data) {

      this.error = undefined;

      const longitude = data.fields.Geolocation__Longitude__s.value;

      const latitude = data.fields.Geolocation__Latitude__s.value;

      this.updateMap(longitude, latitude);

    } else if (error) {

      this.error = error;

      this.recordId = undefined;

      this.mapMarkers = [];

    }

  }

  // Encapsulate logic for Lightning message service subscribe and unsubsubscribe

  subscribeToMessageChannel() {

    if (!this.subscription) {

        this.subscription = subscribe(

            this.messageContext,

            BOATMC,

            (message) => {

              this.boatId = message.recordId;

            }, 

            { scope: APPLICATION_SCOPE }

        );

    }

}

unsubscribeToMessageChannel() {

  unsubscribe(this.subscription);

  this.subscription = null;

}



  // Runs when component is connected, subscribes to BoatMC

  connectedCallback() {

    // recordId is populated on Record Pages, and this component

    // should not update when this component is on a record page.

    if (this.subscription || this.recordId) {

      return;

    }

    // Subscribe to the message channel to retrieve the recordID and assign it to boatId.

    this.subscribeMC();

  }

  

  subscribeMC() {

    let subscription = subscribe(

      this.messageContext, 

      BOATMC, 

      (message) => { this.boatId = message.recordId }, 

      { scope: APPLICATION_SCOPE });

  }

  // Creates the map markers array with the current boat's location for the map.

  updateMap(Longitude, Latitude) {

    this.mapMarkers = [Longitude, Latitude];

  }


  // Getter method for displaying the map component, or a helper method.

  get showMap() {

    return this.mapMarkers.length > 0;

  }

}


boatMap.js-meta.xml


<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="boatMap">

    <apiVersion>48.0</apiVersion>

    <masterLabel>Boat Map Component</masterLabel>

    <description>Component to display a given boat&apos;s location!</description>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

    </targets>

    <targetConfigs>

        <targetConfig targets="lightning__RecordPage">

            <objects>

                <object>Boat__c</object>

            </objects>

        </targetConfig>

    </targetConfigs>

</LightningComponentBundle>

Comments

Popular posts from this blog

Lightning Web Components Specialist Superbadge Solution Boat Tile Component

Lightning Web Components Specialist Superbadge Solution Boat Search Results Component

Lightning Web Components Specialist Superbadge Solution Boat Search Form Component