Wednesday, March 11, 2020

How To Check Whether CheckBox Is Checked/Selected/Ticketed Or Not in LWC

If you want to check this functionality we can relay on the event object of the java script which will tells you whether check box is selected or not.

checkboxSelection.html

<template>
 <lightning-input type="checkbox" label="" onchange={selectDeselectAll}>
    </lightning-input>
</template>

checkboxSelection.js

import { LightningElement} from 'lwc';
export default class CheckBoxClassDet extends LightningElement
{
    
 selectDeselectAll(event) {
        if (event.target.checked)
  {
    console.log('Check box is checked');
  }
  else
  {
    console.log('check box is unchecked');
  }
}

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

Record Is Not Createable Issue In LWC

Most of the times you will receive this error when your using the base lightning components in your application.

Recently I got the same error while I'm using the <lightning-record-form > base component in one of the LWC component.My use case is just to display the record details basis on the given record id and with set of specified fields.

RecDetails.html

<template>
<lightning-record-form 
        mode="readonly" 
        columns="2" 
        object-api-name="WebSite_Details__c" 
        record-id={recId} 
        fields={objFields} >
        </lightning-record-form>
</template>

RecDetails.js

import { LightningElement,api,track,wire } from 'lwc';
import Lan_FIELD from '@salesforce/schema/WebSite_Details__c.Language__c';
import Site_FIELD from '@salesforce/schema/WebSite_Details__c.Site__c';
import Site_FIELD from '@salesforce/schema/WebSite_Details__c.Company__c';

export default class CallPopup extends NavigationMixin(LightningElement){
    @track objFields = [Site_FIELD, Site_FIELD,Lan_FIELD];
    @track recId;
 
//Wired Method Which Returns Record id
   @wire(fetchWebDet)
    wiredfetchWebDet({ error, data }) 
    {
         
        if (data) 
            {
 this.recId = data; // Dynamically assigns the record from the response
   
     }
 }
}

When I'm executing the component I was getting the same error Record Is Not Createable.
Then I started debugging the user related profile details and I figured out the user is not having an access to create a new record.

Interesting Point To Be Noted Here Is:

But still I'm not trying to create any new record,just trying to display the record which is already exist but it's internally trying to create a new record but logged in user is not having a create access on the specified object so it's failing.

If you look at the code I'm fetching the record id dynamically from wired method and assigning to it recId which is record Id in my case.So,here what is happening is the <lightning-record-form > will display the record details in view mode in case if record-id value is available if not then it will try to create a new record.

When the component got rendered this recId is not available so it's trying to create a new record that is why it's causing issue.

Solution:

Simple if condition which checks the whether record id is available would solves this problem.So,please invoke <lightning-record-form > if and only if record id is available.If record id is not available don't invoke the <lightning-record-form > .This solves the issue.Please find the update code below.

<template>
 <template if:true={recId}> //This if check solves your problem
  <lightning-record-form 
   mode="readonly" 
   columns="2" 
   object-api-name="WebSite_Details__c" 
   record-id={recId} 
   fields={objFields} >
  </lightning-record-form>
 </template>
</template>



Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!




Thursday, February 27, 2020

How To Update SFDX CLI to Latest Version in LWC

If you want to know the latest version of your sfdx cli and you want to update to latest version please follow the below steps.

On Window Machines:

To Check The Current Version:

 Goto Start and type cmd to open the command prompt .Then type command called sfdx press enter.

  • If it's already in latest version below screen will be displayed
  • If it's not up to date then you will receive an warning as shown below.Suggesting to update to the latest version. In my case current version is 7.13.0 and latest version is 7.37.1.

How To Update To Latest Version:
  • Open command promt
  • Type command sfdx update and enter
  • If you receive any warning then use command npm update --global sfdx-cli


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

Tuesday, February 18, 2020

How To Open (Url Format) Visual Force Page in Lightning Experience

If you want to open/preview the visual force page in salesforce lightning experience,do you know  how to construct the final url?if not ,this post will help you with the necessary details.

Url format in Classic:

   BaseUrl + '/apex/' + Your PageName +'?AnyQueryParams=xxx'

Url format in Lightning :

  BaseUrl + '/one/one.app#/alohaRedirect/apex/' + Your PageName +'?AnyQueryParams=xxx'

Let take an example your page name is call and your passing the mobile as query param.The complete your will be like below.
https://srinivas4sfdc--dev.lightning.force.com/one/one.app#/alohaRedirect/apex/Call?mobile=8884876772


Output:





Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

Monday, February 10, 2020

How To Search/Open Record Detail Page in Live Agent Using REST API

In my previous posts we have seen how to send the pre-chat details,how to store pre-chat details in transcript object.

In this post I will explain how to perform the search in specified object with given filed names and details.If record found with given criteria how to open this record in chat details automatically .This in turn will helps the agents to save the time to look for the record by doing the manual search to answers the customer.

The key area that we need to look at is "entityMaps" array in prechatdetails and "prechatEntities" array .
  • entityMaps - Store object api name search field name and it's values
  • prechatEntities - which will stores the search object,search field,perform the search or not,create a new if not exist and whether to do exact match or not. 
{
   
   "organizationId":"00XXXXXXxfQ",
   "buttonId":"573xxxxxl",
   "deploymentId":"572xxxxxx9",
   "userAgent":"",
   "language":"en-US",
   "screenResolution":"1920x1080",
   "visitorName":"John A",
   "prechatDetails":[
       {
         "label":"search field api name",
         "value":"value for the search field",
         "displayToAgent":true,
         "transcriptFields": [],
          "entityMaps":[
            {
               "entityName":"object api name",
               "fieldName":"search field api name"
            }
         ]
      }
     
   ],
   "prechatEntities":[
      {
         "entityName":"object api name",
         "showOnCreate":true,
         "entityFieldsMaps":[
            {
               "fieldName":"field api name",
               "label":"field api name",
               "doFind":true,
               "isExactMatch":true,
               "doCreate":false
            }
         ]
      }
 ],
   "receiveQueueUpdates":true,
   "isPost":true
}

Sample Request:


  • Object To be Searched - Booking_Details__c
  • Filed Name to be Searched - Pnr__c
  • Field value - PNR_3563788883

{
   
   "organizationId":"00XXXXXXxfQ",
   "buttonId":"573xxxxxl",
   "deploymentId":"572xxxxxxx9",
   "userAgent":"",
   "language":"en-US",
   "screenResolution":"1920x1080",
   "visitorName":"John A",
   "prechatDetails":[
       {
         "label":"Pnr__c", // search field api name
         "value":"PNR_3563788883",//Value for pnr to be search
         "displayToAgent":true,
         "transcriptFields": [],
          "entityMaps":[
            {
               "entityName":"Booking_Details__c", //object api name
               "fieldName":"Pnr__c" //search field api name
            }
         ]
      }
     
   ],
   "prechatEntities":[
      {
         "entityName":"Booking_Details__c", //object api name
         "showOnCreate":true,
         "entityFieldsMaps":[
            {
               "fieldName":"Pnr__c", //search field api name
               "label":"Pnr__c", //search field api name
               "doFind":true, //tells to do search or not
               "isExactMatch":true, // do exact match value or not
               "doCreate":false // want to create if not found the record
            }
         ]
      }
 ],
   "receiveQueueUpdates":true,
   "isPost":true
}

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!




Thursday, January 30, 2020

After Update Trigger In Salesforce Apex

Trigger Scenario:

Lets take a sample use case when an Opportunity stage has been changed to Closed-Won ,I want to create a new Invoice(custom object) record with below data mapping.
  • Invoice Opportunity - Same Opportunity where Stage has been modified.
  • Invoice Account - Account Related To This Opportunity.
  • Invoice Total Quantity - The sum the quantity of all opportunity line items(opportunity products) related to the same Opportunity.


The relationship between all these objects as below




Source Code:


trigger OpportunityTrigger on Opportunity (after update)
{
    if(Trigger.isAfter && Trigger.isUpdate)
 {
  OpportunityTriggerHandler.opportunityAfterUpdate(Trigger.new,Trigger.oldMap)
 }
}


Public Class OpportunityTriggerHandler
{
  public static void opportunityAfterUpdate(List<Opportunity> TriggerNew,Map<Id,Opportunity> TriggerOldMap)
  {
   Set<id> setOppIds = new Set<id>();
   Map<Id,Decimal> mapOppIdtoSumOfLineitems = new Map<Id,Decimal>();
   for(Opportunity opty:TriggerNew)
   {
    if('Closed Won'.equalsIgnoreCase(opty.StageName) && opty.StageName!=TriggerOldMap.get(opty.Id).StageName)
    {
     setOppIds.add(opty.id);
    }
   }
   
   if(!setOppIds.isEmpty())
   {
    List<Invoice__c> listInvocesToInsert = new List<Invoice__c>();
    for(Aggregateresult agr:[SELECT sum(quantity) qunty,Opportunityid FROM Opportunitylineitem WHERE Opportunityid IN:setOppIds GROUP BY Opportunityid])
    {
                mapOppIdtoSumOfLineitems.put((id)agr.get('Opportunityid'),(decimal)agr.get('qunty'));
    }
    
    for(Opportunity op:TriggerNew)
    {
     if('Closed Won'.equalsIgnoreCase(op.StageName) && op.StageName!=TriggerOldMap.get(op.Id).StageName && mapOppIdtoSumOfLineitems.containsKey(op.id)
     {
      Invoice__c inv = new Invoice__c();
      inv.name = 'Trigger-'+op.Name;
      inv.ParentAccount__c=op.Accountid;
      inv.ParentOpportunity__c=op.id;
      inv.Discount__c=mapOppIdtoSumOfLineitems.get(op.id);
      listInvocesToInsert.add(inv);
     }
   }
   if(!listInvocesToInsert.isEmpty())
    Database.insert(listInvocesToInsert,false);
   }
  }
}

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.



Hope this helps you..Enjoy..!




What is Full Form Of LWC?

LWC stands for Lightning Web Components .This will be used for building the components in lightning experience (like aura ).
  • These will uses html,modern java script and css.
  • It uses core web components standard.
  • Because it’s built on code that runs natively in browsers, Lightning Web Components is lightweight and delivers exceptional performance.
  • The existing aura and lwc components can co exist in lightning experience.
For more information please refer salesforce documentation.

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.





Hope this helps you..Enjoy..!


Monday, January 27, 2020

How To Deploy Lightning Web Components(LWC)

If you want deploy Lightning Web Components( LWC) using the change set please use the below steps.

  • Create an outbound change set.
  • Click on Add to add the components.
  • Select Component Type as "Lightning Web Component Bundle".

  • Select the one you want to deploy and add for deployment.



Hope this helps you..Enjoy..!



Sunday, January 26, 2020

How To Access Custom Permission In Validation Rule and VF Pages

To refer the custom permissions assigned to users through permission sets/profles in validation rules/pages please use below code

In Validation Rules/VF Pages

$Permission.CustomPermissionApiName

Example:

$Permission.Srinivas_4SFDC

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

Custom Permissions Are Not Working In Apex

Lets assume you have created a custom permission and it's assigned to user through permission sets.

Now when your referring the same value in apex for the assigned user it's still giving a false instead of the true value .

This could be happening because of the  Session Activation Required setting is enabled on the permission set level.

Please disable this and try it out probably it should work.





Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

How To Access Custom Permission in Apex

  • Let's assume you have created a custom permission and it's been assigned to permission set or profiles.
  • Now we can refer the same custom permission in apex to check whether it's enabled for logged in user or not.
  • We use will the checkPermission() method from the FeatureManagement class for the same.

Boolean enabSet = System.FeatureManagement.checkPermission('Custom Permission APi Name');
System.debug('enabSet..'+enabSet);

Example:
Boolean enabSet = System.FeatureManagement.checkPermission('SreeTest');
System.debug('enabSet..'+enabSet);

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.



Hope this helps you..Enjoy..!

Friday, January 24, 2020

How To Configure Console Components In Lightning Console Applications

Unfortunately Salesforce doesn't support console components in lightning experience.

If your existing component is linked to a visual force page and then you want to use this component as a console component in lightning experience the workaround is below.

1. Goto Service Setup

2. Open the App Manager Under User Interface Section

3. Select the application where you want to add console component and Click on Edit

4. Select Utility Items Under App Settings



5. Click on Add Utility Items and Select Visual Force Page option

6. Please give console component name and it's related visual force page(your vf page is not shown)

7. Your component is ready and it's available in the bottom left.


Please comment or write us if you have any queries/requirements.

Please follow,bookmark,subscribe this site to receive daily updates.

Facebook - https://www.facebook.com/ILoveCodingYou/?ref=bookmarks

Hope this helps you..Enjoy..!

How To Disable The Switch To Lightning Experience For An User

If you want to disable to switch to lightning experience link a user ,please follow below steps.

1. Identify the list of users to whom you want to disable this feature

2.Find out all the profiles related to these list of users

3. Goto each profile and Click on Edit

4. Uncheck the Lightning Experience User setting under the Administrative Permissions.


5. Now users will not get this switch permission .

Note:

This entire flow what we discussed above will disable this feature for all the users under the same profile.

If you want to do it for specific user disable Lightning Exp User at profile completely and create a permission set with Lightning Experience User enabled and assign permission set to set of people who required this permission.


Please follow,bookmark,subscribe this site to receive daily updates.

Facebook - https://www.facebook.com/ILoveCodingYou/?ref=bookmarks


Hope this helps you..Enjoy..!

How To Restrict The Record Edit/Modification Access Only To Record Owner and System Admin

If you have a requirement like the record can only be modified either by the owner of the record or the system administration .Other than this if any user tried to modify the record we shouldn't allow them to modify it.

Please use the validation rule to achieve this with below conditions check.

AND( 
     NOT(ISNEW()),
     NOT(OR($Profile.Name == 'System Administrator', $User.Id == OwnerId))
   )


Please follow,bookmark,subscribe this site to receive daily updates.

Facebook - https://www.facebook.com/ILoveCodingYou/?ref=bookmarks


Hope this helps you..Enjoy..!

Wednesday, January 8, 2020

How To Populate A Map With List or Set (Where Collections As a Value) in Salesforce

As a developer most of the times we will be working on collections.One of the most common used collection in salesforce is maps.

Creating a simple maps(value as a string,integer,object etc..) is very easy
  • Map<String,String>
  • Map<String,Integer>
  • Map<key,objects>
The real picture comes into scenario when we want to build some complex maps(where value of a map it self again a collection like list,set etc) 
  • Map<String,list<Account>>
  • Map<integer,set<integer>>
  • Map<AccountId,list<Conatct>>
Most common mistakes that we do while building this complex maps are
  • Old value gets overrides by new values.
  • When your in loop you map always ends up with just holding the last record in list/set.
  • Didn't checking whether value is already is exist or not.
Scenario:

Let take a take I want to create a map which will takes case status as key and it's value is all the cases comes under the same status.

Map<String,List<Case>> mapStatusToCases = new Map<String,List<Case>>()

for( Case cs: [SELECT id,Status,CaseNumber FROM Case limit 20])
{
 //Check whether with same status any record is already is added to map or not
 
 if(mapStatusToCases.containsKey(cs.Status)) 
 {
    // If you directly put this case into the map it will overrides all the existing cases,
   // which is not correct.So get all the existing records and store it list/set.
  List<Case> existingCase = mapStatusToCases.get(cs.Status);
  //add this new record to existing list  
  existingCase.add(cs);
  // now put the same status into the map with all latest case records(existing+new),
  // because key is same so it will overrides existing values with this latest list
  mapStatusToCases.put(cs.Status,existingCase); 
 }
 
 else // this executes if the status is not there in map(it means coming first time)
 {
     //prepare variable of map value type
  List<case> lstNewCases = new List<Case>();
  // adding a new record
  lstNewCases.add(cs); 
  // add the new status as a key and case as a value into map
  mapStatusToCases.put(cs.Status,lstNewCases); 
 }
}

System.debug('All Key Set...'+mapStatusToCases.keySet());
System.debug('All Values in Map...'+mapStatusToCases.values());
System.debug('Complete Map Details...'+mapStatusToCases);

For better understanding in above I have written each statement in a separate line. The same code can also be written in an optimized way as shown below.Both are valid and same.


Map<String,List<Case>> mapStatusToCases = new Map<String,List<Case>>()

for( Case cs: [SELECT id,Status,CaseNumber FROM Case limit 20])
{
 //Check whether with same status any record is already is added to map or not
 
 if(mapStatusToCases.containsKey(cs.Status)) 
 {
  //this statement mapStatusToCases.get(cs.Status) will returns the list
  //So,I'm adding new record to existing list directly
  mapStatusToCases.get(cs.Status).add(cs); 
 }
 
 else // this executes if the status is not there in map(it means coming first time)
 {
     //Delcared a new list and directly adding a new record to that
  mapStatusToCases.put(cs.Status,new List<Case>{cs}); 
 }
}

System.debug('All Key Set...'+mapStatusToCases.keySet());
System.debug('All Values in Map...'+mapStatusToCases.values());
System.debug('Complete Map Details...'+mapStatusToCases);

OutPut:




Please watch this space more useful stuff.

Please follow,bookmark,subscribe this site to receive daily updates.

Facebook - https://www.facebook.com/ILoveCodingYou/?ref=bookmarks


Hope this helps you..Enjoy..!







Monday, January 6, 2020

Origins may not contain paths or queries, since they are not part of the origin in Salesforce

You might encounter with this while adding your community URL or domain address in CORS or While setting up the Snap Ins(Known as (Embedded Service Chat).

The error indicates the url we are should not have any paths and we should take only the url till .com/.in/.domain etc..

If you look in this  scenario the url needs to be added is

https://srinivas4sfdc-developer-edition.ap1.force.com/HelpCust

The one highlighted in yellow can be considered as path or queries.So,please copy your url till the domain(till ends with .com/.in/.edu etc) name not the full url.

The Final url we need to add in CORS or SnapIns settings is 

https://srinivas4sfdc-developer-edition.ap1.force.com/


Hope this helps you..Enjoy..!