Saturday 6 July 2019

Events in Lightning web components (LWC) | Communicate with Events

In this post we will talk about how to use the lightning web component events to communicate between components. Events in Lightning web components are built on DOM Events, a collection of APIs and objects available in every browser. Here we will be see how to the events using the CustomEvent interface and publish-subscribe utility.

Component Communication through events

There are typically 3 approaches for communication between the components using events.

  1. Communication using Method in LWC ( Parent to Child )
  2. Custom Event Communication in Lightning Web Component (Child to Parent )
  3. Publish Subscriber model in Lightning Web Component ( Two components which doesn't have a direct relation )
NOTE:- If you want to communicate the Lightning web component with Visualforce page then we can use Lightning Message Service (LMS).

Tuesday 2 July 2019

Field Level Security in SOQL With SECURITY_ENFORCED

Salesforce introduce the "WITH SECURITY_ENFORCED" clause in Spring 19 as beta. By using With SECURITY_ENFORCED clause in SOQL we can check the field and object level security in SOQL. To use this, just add the WITH SECURITY_ENFORCED clause in SOQL SELECT queries. If there are any fields or objects referenced in the SELECT clause that are inaccessible to the user, an exception is thrown and no data is returned

Here is sample code :-


Now we don't need to check field accessibility in Apex using Schema function. Before to With SECURITY_ENFORCED we used to check field level security like below

if( Schema.SObjectType.Account.Fields.Name.isAccessible() &&
    List<Account> accList = [Select Name,Phone from Account Limit 100];

Now we just need to add "With SECURITY_ENFORCED" in SOQL query like below code :-

   List<Account> accList = [Select Name,Phone from Account WITH SECURITY_ENFORCED ];

} catch( System.QueryException ee) {

    System.debug('You dont have access to all Account fields ');

  1. With SECURITY_ENFORCED is available in Apex only.
  2. Available in API version 45.0 or greater. This is available in Beta. 

Please check below post for more detail

Amit Chaudhary