Saturday, 9 January 2021

                                         Configuration File Tags

apiVersion:- A double value that binds the component to a Salesforce API version. To check the current version, take help of this knowledge article.

description:-A short description of the component, usually a single sentence. Appears in list views, like the list of Lightning Components in Setup, and as a tooltip in the Lightning App Builder and in Community Builder.

When you hover your mouse to the custom component deployed to the org, you can see the description with the label.

isExposed:-A Boolean value. Exposes the component in all orgs, and in Lightning App Builder and Community Builder. To make a component usable in a managed package, set isExposed to true. To make a component usable in Lightning App Builder and Community Builder, set isExposed to true.

masterLabel:-The title of the component. Appears in list views, like the list of Lightning Components in Setup, and in the Lightning App Builder and in Community Builder.

targetConfig:- It is subtag of targetConfigs and used for different page type configuration. For Example:-

<targetConfig targets=”lightning__RecordPage”>

<targetConfig targets=”lightning__AppPage, lightning_HomePage”>

targets:-The targets attribute value that you specify must match one or more of the page types that you listed under <targets> for the component. It Supports the property and objects subtags.

property:-Specifies a public property of a component that can be set in Lightning App Builder or Community Builder. The component author defines the property in the component’s JavaScript class using the @apidecorator.

objects:-A set of one or more objects the component is supported for. This tag set works only inside a parent targetConfig that’s configured for lightning__RecordPage. Specify the objects tag set only once inside a targetConfig set. Supports the object subtag.

 Note

object:-Defines which objects the component is supported for. Use one object tag for each supported object. You can’t use ‘*’ to denote all objects.

 

Html

<template>
    <div class="slds-m-around_small">
        <strong>
            Metadata File Example {message} <br/>
            page no  : {pageno}
        </strong>
    </div>
</template>

Javascript

import { LightningElement,api } from 'lwc';

export default class MetaExample extends LightningElement {
    @api message;
    @api pageno;
}

xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
     <isExposed>true</isExposed>
    <masterLabel>Metadata File Configuraton</masterLabel>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightningCommunity__Default</target>
        <target>lightningCommunity__Page</target>
        <target>lightning__Tab</target><!-- Winter 20 -->
        <target>lightning__Inbox</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage" >
            <property name="message" type="String" label="Welcome Message"/>
            <property name="pageno" type="Integer" label="Page No" />
            <objects>
                <object>Contact</object>
              </objects>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>



 Getter property in Lightning web components

1. Use getter property if you want to modify the property before you use in template

2. Use getter property when you don't  want to create a variable

html

<template>
    <lightning-card title="Getter Property"  icon-name="custom:custom14">
     <p> Passing variable without declaring variable : {passProperty}</p>
     <p> changemessage :  {changemessage}</p>
    </lightning-card>
</template>

Js

import { LightningElement } from 'lwc';

export default class GetProperty extends LightningElement {
    msg='Test';
    get passProperty(){
        return 'Without Declaring Variable';
    }
    get changemessage(){
        return this.msg+'-->'+'add value';
    }
}

xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
   <isExposed>true</isExposed> 
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>


Monday, 4 January 2021

   Render Multiple Templates

You may want to render a component with more than one look and feel, but not want to mix the HTML in one file. For example, one version of the component is plain, and another version displays an image and extra text. In this case, you can import multiple HTML templates and write business logic that renders them conditionally. This pattern is similar to the code splitting used in some JavaScript frameworks.


Note

NOTE Although it’s possible for a component to render multiple templates, we recommend using an if:true|false directive to render nested templates conditionally instead.

Create multiple HTML files in the component bundle. Import them all and add a condition in the render() method to return the correct template depending on the component’s state. The returned value from the render() method must be a template reference, which is the imported default export from an HTML file.


In this example, the template references are templateOne and templateTwo.

miscMultipleTemplates.js

import { LightningElement } from 'lwc';
import templateOne from './templateOne.html';
import templateTwo from './templateTwo.html';

export default class MiscMultipleTemplates extends LightningElement {

    templateOne = true;

    render() {
        return this.templateOne ? templateOne : templateTwo;
    }

    switchTemplate(){ 
        this.templateOne = !this.templateOne
    }
}

xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>47.0</apiVersion>
    <isExposed>true</isExposed> 
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>


templateTwo.html

<!-- templateTwo.html -->
<template>
    <lightning-card title="Template Two">
        <div>
            This is template two.
        </div>
        <p class="margin-vertical-small">
            <lightning-button label="Switch Templates" 
                onclick={switchTemplate}>
            </lightning-button> 
        </p>
    </lightning-card>
</template>


templateOne.html

<!-- templateOne.html -->
<template>
    <lightning-card title="Template One" icon-name="custom:custom14">
        <div>
            This is template one.
        </div>
        <p class="margin-vertical-small">
            <lightning-button label="Switch Templates" 
                onclick={switchTemplate}>
            </lightning-button> 
        </p>
    </lightning-card>
</template>

Saturday, 19 December 2020

Lightning components: can helpers call other helpers

You can definitely call another function within the same object using the this keyword.  Below Example doesnt make sense but it demonstrates the functionality of code

Lightning component : 

<aura:component >

    <input type="button" onclick="{!c.buttonClicked}" value="Click Me" id="myButton" />

</aura:component>

Controller :

({

    buttonClicked : function(component, event, helper) {

        helper.callHelper(component, event.target.id);

    }

})

Helper:

 ({

    callHelper : function(component, buttonId) 

    {

        console.log('call1',buttonId);

     this.helper1(component, buttonId,'Test');  

    },

    helper1 : function(component, buttonId, newLabel)

    {

        console.log('call2',buttonId);

       console.log('call3',newLabel);

    }

})

Wednesday, 16 December 2020

 Permission to Write Apex Code

 They need the Author Apex permission. Ticking this box will result in them being assigned a lot of other permissions as well though.

Granting Author Apex permission also gives the user the following permissions:

  • Modify All Data
  • View Setup and Configuration

Granting Modify All Data also gives the user the following permissions:

Read, Create, Edit, Delete, View All, Modify All on all standard and custom objects

  • Edit Events
  • Edit Tasks
  • Manage Public List Views
  • Manage Public Templates
  • Run Reports
  • Transfer Record
  • View Setup and Configuration
  • Manage Public Documents
  • Import Leads
  • Transfer Leads
  • View All Data
  • Use Team Reassignment Wizards
  • Manage Categories
  • Convert Leads
  • Import Solutions
  • Create and Set Up Communities
  • Connect Organization to Environment Hub
  • Manage Reports in Public Folders
  • Manage Dashboards in Public Folders
  • Delete Topics
  • Assign Topics
  • Create Topics
  • Edit Topics

Friday, 26 July 2019

          Cache control value control in a static resource:


Private- It specifies static resource data cached on the Salesforce server shouldn’t be shared with other users. The static resource is only stored in cache for the current user’s session.

Public specifies that the static resource data cached on the Salesforce server be shared with other users in your organization for faster load times.

https://salesforce.stackexchange.com/questions/9038/what-does-the-cache-control-value-control-in-a-static-resource

Saturday, 9 February 2019

How to Play YouTube Video In Salesforce Lightning Component


We can play video file in lightning component by 2 ways :


  • From Static Resources.
  • Play Video File Using iFrame Tag.
<aura:component>

  <iframe width="720" height="480" src="https://www.youtube.com/embed/45JRuZOBIKk"></iframe>

</aura:component>


<aura:application>
    <c:videoDemo/>
<!-- here c: is org. default namespace prefix-->
</aura:application>