Posts

Showing posts from March, 2022

Salesforce Fact #365 | Enabling list custom settings

If you are getting only one option while creating a custom settings i.e. hierarchical, then the list custom settings need to be activated in the org. There is an option 'Manage list custom settings type' which can be enabled  from Schema Settings. Reference:  https://help.salesforce.com/s/articleView?id=000269861&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1

Salesforce Fact #364 | Input with no space in LWC

Image
Suppose we have an input in LWC which is similar to the API name field of metadata in Salesforce i.e. it will not contain any spaces. If any space is there it would get removed. We can implement the same in LWC. Attached are the screenshots.

Salesforce Fact #363 | Schedule batch apex using simple CRON expression

We can use CRON expression to schedule a batch apex to run at particular hour intervals. Do you know that you can use shorter expression instead of specifying the exact hours.  Suppose, we have to schedule a batch apex to run every 3 hours MON-FRI starting 12 am from a particular day. Now, it can be scheduled in two ways: /*Specifying each hour value; long syntax TestBatchSchedule tbs = new TestBatchSchedule(); String sch = '0 0 0,3,6,9,12,15,18,21 ? * MON-FRI'; System.schedule('test job', sch, tbs); /*Specifying relative hour value; simple syntax TestBatchSchedule tbs = new TestBatchSchedule(); String sch = '0 0 */3 ? * MON-FRI'; System.schedule('test job', sch, tbs); Note: However, it is not possible to put similar kind of syntax for seconds and minutes. Trying to do so will give error: 'System.StringException: Seconds and minutes must be specified as integers'

Salesforce Fact #362 | HammerTime

Do you know what is HammerTime.  Before every release Salesforce runs all the unit tests in all the orgs. They run it once for the previous release and once for the current release. Then, the results are compared to figure out any issue or bug which can be actioned before the actual release is rolled out. The time for this entire testing process is called HammerTime.

Salesforce Fact #361 | Passing null to apex method from LWC wire service

Image
Do you know while calling apex method from LWC using wire service if we do not want to pass the input parameter, we need to pass null or do not pass the value at all. Passing undefined won't call the apex method. For more details, please check:  https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_wire_method Attached are the screenshots.

Salesforce Fact #360 | Delete trigger on child object in MD relationship

Do you know the delete triggers on child object are not fired in case of master-detail relationship. When we are deleting the parent record, it will delete all the related child records using cascade delete but the child object delete triggers are not fired. In order to execute the trigger, the child records need to be deleted individually.

Salesforce Fact #359 | Get first value from multi select picklist in flow

Image
Suppose we have a use case where we would like to get the first value of the multi-select picklist and use it further in flow. Now, LEFT(), FIND() etc. functions cannot be applied on multi-select picklist values. So, as a workaround, in flow we can define a text variable with the default value set as the value of the multi-select picklist. And after that, we can parse the data to get the first value. In this example, we have a multi-select picklist field on Account and we are populating the description field value with the first value selected in the multi-select picklist. Attached are the screenshots.

Salesforce Fact #358 | Access recordTypeId in pageBlockTable

Image
While working with recordSetVar and pageBlockTable in VF page, if we need to get the RecordTypeId for each of the records in iteration we need to use RecordType.Id instead of RecordTypeId. Attached are the screenshots.

Salesforce Fact #357 | OrganizationType

To know the organization edition, we generally go to the Company Information page. But do you know there is a field OrganizationType which returns the same result in SOQL. The below query returns the organization Id and edition of the org: SELECT Id, OrganizationType FROM Organization Note: this field is not accessible using the $Organization global variable.

Salesforce Fact #356 | Leap year check in flow

Image
We can check whether a particular year is leap year in flow using some formula logic. Attached are the screenshots.

Salesforce Fact #355 | Check converted account in record-triggered flow

Image
Suppose we have a use case where we need to differentiate when an account record is created, whether it is an account created from lead conversion or not. The logic is to be checked in record-triggered flow on account. Now, to achieve this we can create a field on account which would store the company of the lead getting converted. Also, on Lead we can create one formula field to store the company field value. The idea is, company is a required field on Lead and it would always have some value when the lead is getting converted. So, we can define a mapping from the Lead company formula field to the custom field created on account. In the record-triggered flow, we can check whether the value of the custom field is populated or not to determine whether this is a converted account.  Note: The custom field on account is only for the lead conversion purpose and need to be exposed in the UI, and also should not be updated from anywhere else. In this example, we are updating the description o

Salesforce Fact #354 | ConvertedDate in Lead

Do you know there is a field ConvertedDate on Lead which stores the date on which the lead was converted. It is a date type field. Suppose we would like to find the no. of leads converted group by the converteddate. We can use the below SOQL for this purpose: SELECT Count(Id), ConvertedDate FROM Lead WHERE ConvertedDate!=NULL GROUP BY ConvertedDate 

Salesforce Fact #353 | Pass value as object structure to child LWC

Image
Suppose we have a use case to pass object like structure data from parent LWC to child LWC. Now, generally we pass individual values considering public property for each of the attribute. But do you know you can pass the data as an object structure as well. This will reduce the number of public properties in the child as the single object structure would be acting as the public property. In this example, we have simple input fields for capturing the employee name and years of experience and that we are passing as an object structure to the child component. Attached are the screenshots.

Salesforce Fact #352 | CALENDAR_QUARTER() in SOQL

Do you know we have a CALENDAR_QUARTER() function in SOQL. It returns the values 1, 2, 3 and 4 for the date value ranges 1st Jan - 31st Mar, 1st Apr - 30th Jun, 1st July - 30th Sep and 1st Oct - 31st Dec respectively. Suppose, we need to find out the no. of account records created in each of the quarter. We can use GROUP BY on the quarter value using the below SOQL: SELECT CALENDAR_QUARTER(CreatedDate), Count(Id) FROM Account GROUP BY CALENDAR_QUARTER( CreatedDate )

Salesforce Fact #351 | Call reusable child component's public method from parent in LWC

Image
Suppose we have a LWC component which has been used multiple times as child in the same component. It is like the component has been reused. Now, the component has a method which does some processing on the value associated with that component. But what if we want to call it from the parent component. Well, well!! you just need to annotate the  method  in child component with @api. Now, you can call this  method  straight from the parent component. In this simple example, we have a child component which contains text input field and a delete button to remove the content of that input field. Now, the same component has been used twice in the parent component. Now, if we want to call the  method  associated to the particular child component reference, we can make use of some data-id attribute to uniquely identify the component reference, template.querySelector() and call the  method  related to that child component accordingly. For this we need to annotate the child component method with

Salesforce Fact #350 | Screen flow: setting default picklist value from custom label

Image
Suppose we have a use case where we have a screen flow which is used by the users to create accounts. The account type field is also an input in the screen. Now, we want to enable users to create accounts only with a particular type for certain period of time. On the other hand, for certain period of time they would be able to select any type value from the available list of values. So, we would like to make it configurable. We can achieve this using custom label and some component visibility option. In this example, we have created a custom label for storing the account type picklist default value. When it is storing a value, the user can create account records with that particular type only. When this value is NULL, the user would be able to choose any value from the available list of values. We have used component visibility option accordingly. Attached are the screenshots.