Thursday 23 June 2022

Super Simple Way To Check SOQL Execution Time

 In many scenario's we come across to know the query execution time which mainly helps in performance tuning and Improving the code not to fall under any governor limits.

Ex: In Production around with lakhs of record how the query performing? If we know the execution time then can think of improvisation.

Step1 : Login To Salesforce --> Developer Console --> Debug --> Select "Change Log Levels" --> General Trace Setting For You --> Debug Level Action --> Add/Change --> It opens "Change Debug Level" Pop Up -->Set "Profiling" --> "Finest"


Step 2 : Write the query in anonymous window for which we wanted to know the execution time and then verify at the end of execution log to get the execution time details.




Misleading Error Messages / Not Enough Details For Error Messges

 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Task.Whatid

Most of the times we miss to add that field in selection and try to use but in our case its in selection still got that error.

Real Time Scenario We faced this issue when new task field is added on the existing code and Trying to deploy to higher environment.& It took a while to figure out the root cause because same code was working earlier and above mentioned "WhatId" is coming in the SOQL query as well.

Root Cause : Adding the new activity field permission in admin profile which is causing issue, By default activity fields will have access to admin profile not required to mention explicitly and by mentioning explicitly for the new added filed it overridden and has access to only new field and other fields are getting above mentioned error.

Ex: In admin profile under field permissions added readable & edit permission.
<field>Activity.NewCustomField__c</field>

Fix : 
  1. Remove the entries from the package profile file
  2. Change the activity to task    Ex: <field>Task.NewCustomField__c</field>
Troubleshoot & Investigation Steps :
1. Issue occurred during the deployment to higher environment and Deployment happens though api user as per our configuration & It's profile is admin profile .
2. Verify the admin profile changes in the PR & Try to revert and validate the PR.
3. If PR validation success then good to understand the root cause ,If still issue occurs validate the changes incrementally to identify the issue.

Tuesday 14 June 2022

Concurrent Apex Errors - Exp

This issue we face generally when we have long running jobs.

Which one considers as long running job ?

In this context ,Any Synchronous Apex  runs > 5 seconds considers as long running job. 

When we get this error ?

Ex: If in your org governor limit allowed to run 10 concurrent jobs execute at a time and you get 11th job then you see this issue.

Solution ?

Try to move it to asynchronous wherever possible

How to identify which job / Apex causing this issue ?

It will be challenging to identify if you have larger code base /complex business functionality, So raise request to Salesforce to provide the root cause.

In our case we have signed for signature support and Part of proactive monitoring the details of which apex causing issue is shared.

If you don't fix this concurrent apex issue ,What happens ?

It will lead to performance issues & Fails to process the request which suppose to process can lead to business impact.

What is the apex causing issue in our case?

 Inefficient SOQL Query : One of the SOQL query is taking 

Avg Run Time : 9 Seconds

Max Run Time : 18 seconds

Note : This query is been used in frequent polling of our logic ,So definitely required to fix. 

What is the solution for " Inefficient SOQL Query " ?

  1. Verify the query fields & Filter conditions - Query only required fields & Filter should be on indexed fields
  2. Verify the volume of table data - Always have the delete /purge jobs for older data and keep the table light
  3. Enabling the indexing can be done with external id enablement for quick thing
The volume numbers in our case ,Causing long running ?
Around 11 Lakhs records & 3 fields on the filter condition only 1 field is indexed.

Solution : 
  1. Re-Arrange the query to have indexed fields take precedence in the filter condition.
  2. The other filter field is of data type "text area" so that cant be marked as external id to get the benefit of indexing, So 1st convert the data type "text area" to "text" by seeing the impact none of the existing records are >80 char length and future also not expected the same. Then mark that as external id .
  3. Another field is "Boolean" ,So this is not supported type of "External Id" & Need to re-thing enabling the index of this field really going to improve performance.
    • Ex: if the records are 50% yes and 50% no, It doesn't make sense to index this field ?
  4. In our case it's not required to index Boolean field

Monday 13 June 2022

System.LimitException: Regex too complicated

I came across this issue recently in production & The root cause is the length of the string which used in the regex.

Our use case it should verify combination of 2 words in received string & It started failing if the received string length is >369 characters

Ex: Card , Delivery keywords should be verified in the received string and it could be of any order. 

Actual Issue : Its hitting the heap size error 6 MB for synchronous 

Solution :

1. Move the logic to asynchronous as heap size will be 12 MB.

But in our case its not possible to move the asynchronous, Because its should be real time on every record insert this need to be tested and batch job cant be run that many time and future method also has 24 hrs limitation 250000 and on every record entry if that future method called that also hits another governor limit.

2.Split the message and verify the keywords in the smaller chunk message, This approach has been taken and working fine. 



Wednesday 18 May 2022

Summer 22 Regression Issue : Fatal Error : UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support

Summer 22 Release Causing issues in Deployment : 

Issue : GACK error while validating the package / Deploying

"Fatal Error : UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support (XXX)"

GACK  is an error got thrown within application and didn't catch it / handle it gracefully.

Impacted Instance : CS80 

Navigate to know your instance details : Set Up --> Company Information --> Instance

Workaround : Proceed with delta deployment

Root Cause : Package has duplicate entries which is causing the issue of deployment.

Our Case : File Name.layout & File Name.layout-meta.xml

Earlier also had the duplicate entries ,So why now it's causing this issue ?

There is enhancement in the Salesforce validation engine, Earlier it was serial and now it handles in bulk manner.

When it was serial validation used to override the duplicate entries with latest one, Since now entire validation way is changed to improve the performance & It will not allow any duplicate entries with Salesforce Summer Release. 

Why GACK ?

Receiving the GACK error for this scenario is causing lot of trouble in investigating the issue both from Salesforce side & From User side.

EX: If the package is huge and like consider have 5K+ components & There is no way to change the strategy to delta deployment 

So Salesforce Team is working to handle this error gracefully and In future it provides the proper log w.r.t the exact duplicate entry details which helps in troubleshoot quickly.

Final Thoughts : If you are facing the deployment issue after summer 22 release update ,Kindly verify the duplicate entries of your metadata & Hope Salesforce releases knowledge article shortly on this.


Monday 25 April 2022

How to get first element of map without Iteration using Apex in Salesforce ?

 Use Case : You are receiving a Map with only the size of 1 record. So with out iteration /Loop logic how you will fetch the 1st key and value details ?As Map collection directly don't have the index method.

A Map & Set are an unordered collection of elements so its not allowed to access through index.

Convert the Set into List if required to use the indexed value.

The below code helps to fetch the 1st key and value of the Map with out iteration.

Map<String,String> mapNames = new Map<String,String>();

mapNames.put('1001','XYZ');

//Convert the Map KeySet to List and then apply the index ,Set & Map don't have indexing bec of unordering

System.debug('1st Key Of Map:'+ (new List<String>(mapNames.keySet()))[0]);

System.debug('1st Key Value Of Map:'+ mapNames.get((new List<String>(mapNames.keySet()))[0]));




Sunday 20 March 2022

Salesforce Real Time Performance Issues -Optimization Solutions

Performance is one of the area we always fail to notice initially & Deprioritized. It only get the priority when it becomes the bottle neck.

1.Use Case : Service cloud project agent receives a transferred call and A custom component (LWC) should load in modal popup to perform the authentication of customer (Custom logic as per business requirements). It's taking 2 mins to load that modal pop up in one of the test environment & Its intermittent issue.

Root Cause :

  • Unindexed field is been used in the query filter & Record count is around 75K
Fix :
  • Delete unwanted records 
  • Have a schedule delete data job to run on regular basis 
  • Index the field - Marked as external id in our case which automatically creates index on it

After Fix Outcome : There is significant improvement of performance from 2 Min to <  2 Sec

Why intermittent ? 

1.Initally the query taking time and later it was fetching form cache that is the reason it was intermittent.

2.In parallel deployment activity to sand box / Any data load also would have been a reason.

Investigation Steps : 

  • Open the component and see the logic written in life cycle hooks 
  • This case flow :  From CTI --> Apex Class Method called with the required details passed --> Apex method Triggers Platform event  with the details --> LWC component is subscriber --> The received details  will passed to "Apex Class" to get the further details from objects
  • Divide the parts into 2 ,
    • One from CTI to LWC component how much time it is taking & 
    • Second when subscriber passes values to Apex how much time it is taking to written.
  • Drill down deeper into the area where issue exist & Use console logs & Debug logs to notice exact issue location

Friday 21 January 2022

Banking Domain Knowledge

Direct Debit VS Standing Order


Both are schedule payments only to make the customer life easy by paying the bills automatically and giving theire valuable time back to customers


Direct Debit Standing Order
Pull Model Push Model
There could be a variation in the amount to be paid each time till the schedule time Fixed amount always till the schedule period
Ex1:Electicty Bill - The amount will change based on the usage each month,So the organization will pull the amount from your account w.r.t the spent to whom we owe Ex1:Netflix subscription bill payment - It will be fixed according to the plan you choosen earlier and every month fixed amount
Ex2:Phone post paid bill payment - The amount will change based on the usage each month,So the organization will pull the amount from your account w.r.t the spent to whom we owe Ex2:SIP / EMI / Rent per month - which will be fixed according to the plan you choosen earlier and every month fixed amount

Account Switch

All the banks should adher to the rules of Account Switch,If a customer would like to switch from one company bank account to other it should provide the option and Also move all the schedule payments like direct debits and standing orders


Paper Mandate VS E-Mandate