Tuesday, October 12, 2021

Best Practices in Apex

Best Practices in Apex Code


This will not only improve the code quality but also make it easy to enhance in future.

  1. Bulkified code - Use collection like map or list
  2. Avoid DMLs inside loops
  3. Avoid query inside loops
  4. Donot hard code in the code- Use custom labels, custom settings etc
  5. Try to keep each method short so that code is easily understandable
  6. Always put a comment for a class and for each  method
  7. Try to put Null checks where ever it us possible. Use Safe Navigation Operator.
  8. Use try catch block - This will help to capture the scenarios which gets missed in try block.

Please share the blog and leave a comment about your thoughts.
Click here for more blogs.

Sunday, October 10, 2021

How to Execute, Monitor and Abort a batch class in Salesforce

Lets understand how to execute, monitor and abort a batch


How to execute a Batch

Syntax:

<Class name> <object name> = new <class name> ();

Database.executebatch(object name, size of batch);

Difference Between Delete and Remove from Record in Notes & Attachments in Salesforce Lightning Experience

Lets understand the difference Between Delete and Remove from Record in Notes & Attachments in Salesforce Lightning Experience 

We must have seen two buttons on the menu option of file attached in Lightning Experience.

1. Delete

2. Remove from Record

sfdc


Let us understand the difference between these.

When a user clicks one the delete button the files are deleted from all the records(parent/cloned both).

On the other hand, if a user click on the remove from record then the file is deleted only from the record.

Concerns:
There is no option to remove/hide these two from the menu options.
If there is any requirement to run a logic on delete then a trigger can be implemented on content document.

Please share the blog and leave a comment about your thoughts.
Click here for more blogs.