Showing posts with label Salesforce. Show all posts
Showing posts with label Salesforce. Show all posts

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..!

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 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..!







Wednesday, January 1, 2020

Few Scheduled Jobs Got Stopped Working Suddenly in Salesforce

If you have figured out that some of your scheduled jobs got stopped working suddenly.. There could be same issue which we have run into and figure out eventually after some time..

As the year got changed, while scheduling the jobs initially if you have mentioned a year as 2019 or till 2019 in your cron string expression then all your scheduled jobs comes under this category would have been stopped since Jan 1st 2020 at 12:00Am.

There could be some other reasons which might cause the issue but this is the one of route cause we have to cross as year got changed. 

Wish you a happy new year to everyone...



Tuesday, December 31, 2019

typeAttributes in lightning-datatable or lightning:datatable

Basically typeAttributes are the one of the major building blocks of <lightning-datatable>(in LWC) or <lightning:datatable> (in Aura).This will help us to format the data types /output display and attaching some of actions to your data displayed in table at each cell level ,row level or at the columns level.

The typeAttributes are attached to each columns data type when your specifying the columns for your data table in your java script file.

Each typeAttributes is having pre-defined set of attributes/properties basis on the data type of your column (your defining at the time of columns for table).

Usually each column definition will have below properties.

{ 
  label: 'Issue Type',  //Column Header Shown in Table
  fieldName: 'Issue_type__c', //Api name of filed 
  type:"text",   // tells text,date,url,email etc..
  initialWidth: 90 //column width
}

After attaching the typeAttributes the sample code looks like below.The sample code will create a column with name Case Number and Looks like a button ,on click of it you can fire rowAction automatically.


{
        label: 'Case Number',
        type: 'button',
        initialWidth: 90,
        typeAttributes: {
            iconName: 'action:preview',
            title: 'Preview',
            variant: 'border-filled',
            alternativeText: 'View',
            disabled: false,
            label: { fieldName: 'CaseNumber' }, // to assign the value dynamically
            name: { fieldName: 'Case_Age__c' }, // to assign the value dynamically
        }
    },

//other colums

At any time if you want to set any of the typeAttribute object attribute dynamically please use below syntax


  attributeName: { fieldName: 'api name of column/any other variable' }
          

As I have mentioned on the top each typeAttributes will have some set of properties based on the data type of your column.

If you want to know what are the available attributes for each datatype please refer below.




Sample Column Code With typeAttributes:


const datatableColums =[
 //Column 1 of type Url
    {
        label: 'Customer Name', fieldName: 'nameUrl', type: 'url',
        typeAttributes: {
            label: { fieldName: 'Name' },
            target: '_top'
        }
    },
 
 //Column 2 of type button 
 {
        label: 'PNR',
        type: 'button',
        initialWidth: 90,
        typeAttributes: {
            iconName: 'action:preview',
            title: 'Preview',
            variant: 'border-filled',
            alternativeText: 'View',
            disabled: false,
            label: { fieldName: 'Pnr__c' },
            name: { fieldName: 'Pnr__c' },

        }
    },
 
 //Column 3 of type date 
 {
        label: "Closed Date",
        fieldName: "ClosedDate",
        type: "date",
        typeAttributes:{
            weekday: "long",
            year: "numeric",
            month: "long",
            day: "2-digit"
        }
    }
]

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..!