Interview Questions – Lightning Framework – Part 7 – Global Value Providers, Controller Function

Interview Questions – Lightning Framework – Part 7 – Global Value Providers, Controller Function

Checkout earlier posts in interview question series to read previous questions.

Lightning framework is very powerful and tightly coupled with Salesforce resources and Apex. You can use aura reference “$A” to get values from global value providers like Label, Localization, User Details etc.

53. How to get a System Label value in Aura Component?

To get system label in aura component, user $A.get() method. Like $A.get(“$Label.namespace.label_api_name”);

Example - $A.get(“$Label.c.header_name”);

54. How to get current signed in user’s id?

$A.get("$SObjectType.CurrentUser.Id");

55. How to get browser information in component?

Use $Browser global value provider to return information about the hardware and operating system of the browser accessing the application. Example:

var device = $A.get("$Browser.formFactor");
alert("You are using a " + device);

56. How to get current user’s timezone?

$A.get("$Locale.timezone");

57. How to reference a static resource from JavaScript?

Use $Resource global value provider in JavaScript to refer a static resource file. Example:

$A.get('$Resource.ResourceName’) + '/assets/images/avatar1.jpg';

58. How to set attribute value from JavaScript?

Use component.set() method to set an attribute value in JavaScript. Example:

<aura:attribute name=“greeting” type=“String” />

In JavaScript you can set attribute value like below:

component.set(“v.greeting”, “Hello World”);

59. How to get attribute value in JavaScript?

Use component.get() method to get an attribute value in JavaScript. Example:

<aura:attribute name=“greeting” type=“String” />

In JavaScript you can get attribute value like below:

var gettingValue = component.get(“v.greeting”);

60. What is component.find() method and why is it being used?

component.find() method is used to find an element from component markup using aura:id. This method return complete element and can be used to set attribute values of element or performing any other operations like changing CSS classes etc.

<lightning:input aura:id=“nameInput”  value=“Manish”/>

In JavaScript, you can dynamically change the value attribute of above lightning:input-

var inputElement = component.find(“nameInput”);
inputElement.set(“v.value”, “SFDCFacts”);

61. Why we use component.getEvent() method?

component.getEvent() method is used to get a reference of registered component event in component markup. Once the event is retrieved, same can be fired from JavaScript. Example:

<aura:registerEvent name=“onTileSelect” type=“c:TileSelectEvent”/>

You can get above component event in controller:

var tileSelectEvent = component.getEvent(“onTileSelect”);
tileSelectEvent.fire();//fire the event

Read Also:

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Salesforce.com Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

This Post Has One Comment

Leave a Reply

Close Menu