Thursday 23 March 2017

Best Practices of Writing Apex Classes


Ø  Apex code must provide proper exception handling.
Ø  Using Collections, Streamlining Queries, and Efficient For Loops. 
Ø  Avoid SOQL, SOSL Queries or DML statements inside FOR Loops. 
Ø  Should not use Async (@future) methods inside loops. 
Ø  Should use Asynchronous Apex (@future annotation) for logic that does not be executed synchronous.
Ø  We should not use hardcoded IDs as they may cause problem when moved to production.
Ø  When querying large data sets, use a SOQL “for” loop.
Ø  We should prevent SOQL and SOSL injection attacks by using static queries, binding variables or escape single quotes method.
Ø  Should use SOSL rather than SOQL where possible.
Ø  Bulkify your Code. 

Ø  Use of the Limits Apex Methods to Avoid Hitting Governor Limits.

7 comments:

  1. Its really good article.if someone want reads salesforce article.

    Best Salesforce training in Gurgaon
    Looking forward to your response!

    Thanks,
    Mahesh Chandan

    ReplyDelete
  2. Great article on Apexa classes.
    Thanks for sharing Salesforce Online Training

    ReplyDelete
  3. Hi Friend,
    In Admin Dumps below are the question answers are wrong update once.

    46. A user profile has a login hour restrictions set to Monday through A user profile has login hour restrictions set to Monday through Friday 8am to 5pm. It is Tuesday and it is now 5.01 PM.
    Which behavior of the application should the user expect?
    a. The user will be logged out and any unsaved work-in-progress will be lost
    b. The user will be logged out and any unsaved work-in-progress will be saved
    c. The user will be able to continue working and start new sessions
    d. The user will be able to continue working, but will be unable to start any new sessions

    Ans:d


    52. The marketing team at universal containers wants to send an email to each lead received from its website. The country of the incoming lead should determine the language of the email that will be sent to the lead.
    How can the system administrator automate this process?
    a. Create an email template for each language and an assignment rule to send appropriate template
    b. Create an email template for each language and an auto response rule to send appropriate template
    c. Create an email template for each language and a workflow alert to send appropriate template
    d. Create a single email template and use the translation workbench to translate and send the appropriate template

    Ans:d



    56. Universal containers set the organization-wide defaults for cases to private. When a case is escalated, case ownership changes to Tier 2 support agent.
    How can a system administrator give the sales operation team read/write access to all escalated cases?
    a. Create a case escalation rule.
    b. Create a case assignment rule.
    c. Create a criteria-based sharing rule.
    d. Create an ownership-based sharing rule.
    Ans:c

    ReplyDelete
    Replies
    1. hi, are you sure that incorrect?

      Delete
    2. and the question 5 : )What can an administrator configure for users on the search results?Objects included in the search or
      Fields being searched on for each object.

      Delete

  4. Great presentation of Salesforce form of blog and Salesforce tutorial. Very helpful for beginners like us to understand Salesforce course. if you're interested to have an insight on Salesforce training do watch this amazing tutorial.https://www.youtube.com/watch?v=KKVniZdZVW0

    ReplyDelete
  5. For latest 2018 SP dumps for App Builder, PD1, PD2 MCQ please email - crm2api@gmail.com

    ReplyDelete