Wednesday, May 10, 2017

PAGEREFERENCE BEST PRACTICE

In one of my previous post I told how to redirect to standard salesforce classic and why. To give you the recap .

// ================ This is not recommended ===========
public PageReference customsave() {
    try{
        insert acct;
    } catch (DMLException e) {
        /*do stuff here*/
    }
    PageReference acctPage = new PageReference ('/' + acct.id};
    acctPage.setRedirect(true);
    return acctPage;
}

//========== Recommended way is =======

public PageReference customsave() {
    insert acct; //Error handling removed for brevity. ALWAYS try/catch!
    ApexPages.StandardController sc = new ApexPages.StandardController(acct);
    PageReference acctPage = sc.view();
    acctPage.setRedirect(true);
    return acctPage;
}

In salesforce we have a critical update ticking for another issue where we return the visualforce page reference.
Now it has two security restriction.

  1. With HYPERLINK see here
  2. Returning /apex/page as page reference, Require CSRF Protection on GET requests
When this option is enabled for a Visualforce page, you can’t access that page by entering its URL—/apex/PageName—and plain links to that page using <a> tags don’t work.
Plain links from a page with CSRF checks work, but links to the page do not. For example, if your page has the name PageName, the link <a href="/apex/PageName">Link</a> doesn’t work. Instead, use the URLFOR() formula function, the $Page global variable, or the apex:outputLink component.
<apex:outputLink value="/apex/PageName">Link using apex:outputlink</apex:outputlink>
<a href="{!$Page.PageName}">Link using $Page</a>
<a href="{!URLFOR($Page.PageName)}">Link using URLFOR()</a>
CSRF checks on GET requests also affect how Visualforce pages are referenced from Apex controllers. Methods that return the URL of CSRF-protected pages for the purpose of navigation don’t work:
public String getPage(){
  return '/apex/PageName'; 
}
Instead, use methods that return a reference to the Visualforce page instead of the URL directly.

public class customController {
    public PageReference getPage() {
    return new PageReference('/apex/PageName'); 
  }

  public PageReference getPage1() {
    return Page.PageName; 
  }
}


When you use one of these methods to link to a page, Visualforce adds the required CSRF token to the URL. These are the preferred methods for linking to Visualforce pages, regardless of whether CSRF protection is enabled for the page. These are the only methods available for adding a CSRF token to a URL for a Visualforce page.

Friday, May 5, 2017

Passed DEV 501 transition EXAM !!!!!!!!!!!!

I kept postponing the exam and finally took it on Apr 18, 2017, passed it without any issue.
Anyways if you are planning to take this exam, I would suggest that you take it at the earliest as the transition exam is not that difficult if you know what to study. 
A few other folks mentioned that the actual study guide is a bit unhelpful which I tend to agree with that. With every new release, it will become more complex to pass in single attempt. 


STUDY TOPICS:
  1. Compound fields – Learn the different types of compound fields and understand the considerations and limitations. Pay attention to DISTANCE and GEOLOCATION formulas. 
  2. Advanced Currency Management – review this topic and also pay attention to how you would approach this in SOQL or SOSL. 
  3. How would you manage exchange rates when multi-currency is enabled?
  4. Understand Continuation Calls and why they are needed.
  5. Review best practices for test classes and why the new @testsetup annotation is used. Understand its considerations. 
  6. Review how to query for permission sets in SOQL. Pay close attention to the various aspects of this namely the relationship between the user and permission set and the user license.
  7. Understand the @invocablemethod annotation and how it differs from Process.plugin and the @invocablevariable annotation.
  8. Understand the basics of lighting components. Best to skim through the Lightning components developer guide and understand the first few chapters. 
  9. Pay attention to how you would mock classes for HTTP callouts v/s web service callouts?
  10. Review the web service class and understand what kind of arguments it can accept and return. 
  11. Visualforce best practices
  12. APEX best practices
  13. Order of Execution
  14. Understand how to use the developer console and its components. How can you debug your code using this? (Spend some time on this. I missed some questions on this and they are easy to get!!!!)
  15. Apex charts – Pay attention to the various options and attributes. 
  16. Efficient ways of querying parent-child object SOQL or performing parent-child object DML. 
  17. Roll-up summary considerations.
  18. Know when to pick the best automation tool for a given scenario. 
  19. Review the VF apex: action… tags and understand their usage. 
  20. Finally, skim through the apex and vf developer guides. Note: I was not able to do this in detail due to lack of time but if you have time then go for it. 
Overall if you know the above topics and reviewed the study guide you should pass quite easily.
Good luck and as always, you are free to ask me questions in the comments. 
Here is the link you can get all the information about the topic. please leave your comment I will try to respond as much as I can.

Wish you all the best and thanks for visiting my blog. 




Tips on passing Salesforce AI Associate Certification

  🌟 Motivation to Pursue the Salesforce AI Associate Certification 🌟 The world of technology is in a state of perpetual evolution, and on...