Wednesday, July 10, 2019

How To Check Whether User is In Console or Not in Lightning Experience

Basically if you want to check whether user in Lightning experience console(sales/service consoles in lightning experience not the just lightning experience ) you can use the same sforce console methods which you have used in classic.This method will support in lightning experience with out any changes.

Sample code:

<apex:page> 
<apex:includeScript value="/support/console/42.0/integration.js" /> 
<apex:includeScript value="/support/api/41.0/interaction.js"/> 

<button onclick="openTab();" > Console openPrimaryTab</button> 

<script> 
function inConsole() { 
if (sforce.console.isInConsole()) { 
alert('In console'); 
}else { 
alert('Not in console'); 
} 
}
</apex:page>

Note:
Even after using this if it's not working please check you version of /support/api/42.0/integration.js. If your version is below 42 then it will not work.So,please change the version it will work automatically.

Hope this helped you..Enjoy!..

Saturday, July 6, 2019

Lightning Web Components (lwc) Are Not Showing in SF While Adding To Layout

Even after pushing the lighting web components into sf ,if it's showing in components list but not showing while adding to any layout ,it means your .js-meta.xml file has some issue.

Please check whether <targets> is specified for this component or not.Targets is nothing but where are in places this component can be accessible/usable like App page ,Record detail page or in home page layout.

Proper js-meta.xml will be like

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

Hope this helps you...Enjoy!

Base Lightning Components in Salesforce LWC

In Lightning web components(lwc) we will Base Lightning Components to display the particular record information/to create a record quickly with provided information with out using any custom apex.

List of the available Base Lightning Components are
  • lightning-record-edit-form
  • lightning-record-form
  • lightning-record-view-form

lightning-record-edit-form:

  • This component wrapper accepts the record id to display one or more fields and labels related to that field corresponding to given record id 
  • This will not require any apex because it uses Lightning Data Services to fetch the data
  • This will not support Standard objects like Task and Events.
  • Use lightning-output-field to display data in read only format
  • Use lightning-input-field to edit these fields in edit on record edit page

lightning-record-form:

  • Use this component to build the forms quickly to create a record,view the record or to update the record. 
  • Building the record creation forms is easier than building the form using lightning-record-edit-form and lightning-record-view-form. 
  • This component accepts 4 properties like object name which is mandatory,record id which is optional in case of create record ,mode to specify view/edit/read only and layout type like Full or compact
  • It will also takes care of FLS and sharing rules
 <lightning-record-form  
   record-id="739hchjsh773"  
   object-api-name="Position__c"  
   layout-type="Full"  
   mode="view">  
 </lightning-record-form>  

lightning-record-view-form:

  • Use this component when you want to dispaly the record on view mode
  • This will not require any apex because it uses Lightning Data Services to fetch the data
  • This will not support Standard objects like Task and Events.
  • It will also takes care of FLS and sharing rules.

For more information refer:

Hope this helps you...Enjoy!

How To Access Salesforce Org Data in Lightning Web Components

In Classic if you want access/create the Salesforce Data we can either use some Standard Controllers or Custom controllers .Similar to Classic in Lighting Web Components also you can use two different ways to access/create the data into Salesforce objects or to show the Salesforce objects data in Lightning Web Components.

  1. Base Lightning Components
  2. Wire Services

Base Lightning Components:


These are the standard salesforce components which will be used to view the record,to edit the record and to view the record in read only mode.

Benefits:
  • Doesn't require apex code
  • Field labels are displayed based on org default
  • It's has built over Lighting UI API and Lightning Data Service API
  • It access models Static and Dynamically
  • Metadata Aware
  • Custom rendering of data
  • Custom layouts and multi column layouts



Wire Service:

Wire service will use Lighting /UI API Module and Lightning Data Service to fetch the data from the Salesforce Servers/Objects and to show it in the components.Basically we have to import the wire adapters into our lighting web components js file in order to build the communication between the components and servers.The results returned from the wire adapter will be stored either in property or function.

  • Lighting /UI API Module : It will contains bunch of wire adapters(small segment of code) and some JS APIs. These wire adapters will be used to fetch the data from the servers and these JS APIs if you want to modify this data or to push the data into servers.

  • Lightning Data Service : It will act an interface between the wire adapters and data base to get the data from the data base into the adapters. Basically adapters will interacts with Lightning Data Services to fetch the data from the data base.









 Hope this helps you...Enjoy!