Saturday, 4 April 2020

Some Useful Apextips

Weekly Digest of #Apextips- Week 1


Hello Folks,

In this blog, we are going to learn 5 Apextips which developers must now.

So are you guys ready to dive deeper? 

Lets go- πŸ™‹


Apextip 1 : Invocable Method

Lets understand invocable method, write -
before the in the starting of method.
e.g- Class {
Method1 Method2 }
It will run method1 only and not method2 if you call this class from process builder or trigger.

--------------------------------------------------------------------------------------------------------------------------
Apextip 2 : DML exception Database.SaveResults Method

Lets Understand DML exception Tip-
Writing hand


Case: To add multiple records, if single insert is failed then all records insertion is failed.
Solution: Database.SaveResults[] method is used to insert all correct records without exception.πŸ––

Checkout below image 🀞



--------------------------------------------------------------------------------------------------------------------------

Apextip 3 : DML exception Failed record Insertion

Lets learn thisπŸ–

Use Case: I want to use database.result method but if exception occurs then operation should be failed .
Solution : Set the value of database.insert to true. If exception occurs, no record is inserted.🀞

Checkout below image 🀞



--------------------------------------------------------------------------------------------------------------------------

Apextip 4 : issuccess() & getid() methods

Lets understand this tipπŸ™‚

Usecase: I want to get the Id of inserted account Solution: Use issuccess() & getid() methods to get record IdπŸ– issuccess() - Identifies the record created successfully getid() - To get the record Id

Checkout below image 🀞


--------------------------------------------------------------------------------------------------------------------------


Apextip 5 :Extract ID of Deleted Account



Lest understand the last tip of this blogπŸ™‚



Usecase: I want to extract the Id of deleted account
Solution: Use database.delete method to delete accs without exception πŸ–

issuccess()- to check status of delete! getid()-Gets the Id of deleted record




--------------------------------------------------------------------------------------------------------------------------

Hope you guys had learn something new from this Blog. To learn more Apex tips, Stay tuned with us. We post weekly blog of 5 #Apextips.
Feel free to reach us on below contact details.

Thank You

Happy Coding!πŸ˜„


Contact:
Twitter Handle : Lakhan Meghani
Apextips Twitter handle : Apextips
linkedin :                         Lakhan Meghani                        

















No comments:

Post a Comment