Posts

Salesforce Apex Triggers Interview Questions/Scenarios

 Hello, This post is regarding some apex trigger interview questions. These questions are for Novice to Intermediate level developers. I feel these questions/scenarios would be helpful for practice. PS: The questions below are collected from the internet and some of them are which I was asked in the interviews I appeared for. 1.    Create "Sales Rep" field with the datatype (Text) on the Account object. When we create an Account record, the Account's owner name will be automatically added to the sales rep field. When we update the Account owner of the record, then also the Sales Rep will be automatically updated. 2.    Create a field called "Contact Relationship"(checkbox) on the contact object and create the object called "Contact Relationship" which is related to Contacts (Lookup Relationship). Now build a logic when we create contact by checking the Contact Relationship checkbox, a Contact Relationship record will be created automatically for that c...

SFDX Push Error : An object 'ComponentName' of type LightningComponentBundle was named in package.xml, but was not found in zipped directory

Image
 Hello, Nowadays salesforce developers have moved to SFDX and VSCode as their primary IDE. There is one error which has particularly bothered me and my team.  This error occurs when you create a new SFDX project and retrieve all the components, do all the required changes lets say in a lightning web component and try to push the component to salesforce org. This error occurs :  An object 'ComponentName' of type LightningComponentBundle was named in package.xml, but was not found in zipped directory. Solution: Please do check if there is meta.xml file in the component bundle, this error occurs because of missing meta.xml file. For some weird reason, the meta.xml file is not retrieved with the component. If that is the case, then one solution is to create a meta.xml file manually under the component folder with the general XML configuration as below: <? xml  version = "1.0"  encoding = "UTF-8" ?> < LightningComponentBundle   xmlns = "http://soap....

Enable console.log and alert statements in LWC

Hello, This post is about a very small and somewhat confusing error that you come across when you are doing LWC development.  Unexpected console statement. eslint(no-console) Unexpected console statement. eslint(no-alert) Why does this error occur? -       This is because ESLint(Linter tool which analyzes code and throws error, when it finds programmatical bugs, syntactical errors, etc.,) considers using console statements or alert statement as a bad practice -       It is considered as bad practice as console and alert statements are used for debugging purpose and they should not be shipped to the client. What is the solution? To overcome this there are 2 ways: 1.    You can disable ESLint’s rule for the whole JS file export default class accountComponent extends LightningElement { /* eslint-disable no-console */ /* eslint-disable no-alert */ handleClick(event){ console.log('Eve...

Prevent CRUD/FLS violation - isAccessible()

There are certain security tests which salesforce recommends before allowing an application to be used. These tests include permissions, XXS vulnerabilities, etc. One of these is regarding the accessibility of the fields which are being retrieved in your code. This code snippet will help you check the accessibility of your fields included in a SOQL query. IsAccessible() This function of DescribeSObjectResult class, verifies that the logged-in user has permission to access the field before your code retrieves the field from an object via query. Code Snippet : public static Boolean isFieldsAccessible(Map<String, Set<String>> objectFields) {         Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();         Integer globalFlag = 0;         for (String objectName : objectFields.keySet()) {             Integer flag = 0;         ...

Open your scratch org in one click! SFDX Scratch org login batch file

Hello, This batch file opens your scratch org in one click. The whole purpose of this batch file is to reduce the effort of opening the command prompt & typing in the commands. Steps: 1. Create a new file with .bat extension. 2. Copy the below code: @echo off echo WELCOME! REM Below line is added to create a blank new line echo. REM Below line is written to add a delay of 2 secs ping 127.0.0.1 -n 3 > nul echo Below is the list of SFDX orgs REM Below line fires sfdx command which shows you sfdx orgs CALL sfdx force:org:list echo Login initiated REM Below line is written to add a delay of 4 secs ping 127.0.0.1 -n 5 > nul REM Below line is added to create a blank new line echo. echo Opening your scratch org ! REM Below line is added to open your scratch org. Please change the " [scratchorgalias] " by your scratch org's alias. CALL sfdx force:org:open -u [scratchorgalias] 3. Save the file. Now everytime you want to open your scrat...