Thursday, March 3, 2016

Lovely Coding Club

IMG_20160227_115827.jpg


You think you are looking at a crazy group? Nope, we are Girls Who Code Millbrae Club. We play hard and work hard! We break things and fix them quick!


I’m a engineer at Salesforce and my dream of becoming a teacher led me to teach at Girls Who Code Club. First time getting into the classroom with 20+ middle and high school girls was intimidating.  I was so worried about whether the girls will hate me and walk away. This ended up not happening. We had a great time exploring variables, loops and other computer knowledge by building little fun python projects together. We meet every Saturday and now we are halfway through the semester. The girls are still eager to learn and code!

IMG_20160227_115746.jpg


I can’t express in words how exciting I feel to work with the girls. They are so smart and passionate. I enjoy every aha moment when they shout out excitedly “Aha. I’ve got it!”. That makes me rethink why I got into engineering field at the first place and cherish my current job more.

I have no doubt that there will be a future “Grace Hopper” and “Marissa Mayer” among the girls. Way to go girls. Halfway though. You got it!




Thursday, February 25, 2016

Things to watch out for when using Visualforce in Lightning Experience


Lightning Experience is a revolutionary and exciting change for Salesforce. Because Lightning Experience has some differences when compared to the Classic UI, you will need to account for certain things when switch. Here are a couple of things to watch out for to make your Visualforce implementations work in Lightning Experience.




  • After the 2016 Spring release, inline Visualforce not only shows on View pages, but also shows on Create/Edit/Clone pages in Lightning Experience. This is a feature many Customers have asked for. It’s finally live! But will it work with your implementation?


If your current implementation relies on data from a View page, then it might break. For example, if your VF assumes recordId exists and doesn’t do null checks for recordId, then Create/Edit/Clone pages would fail.
Here’s a code example.

1. Create an Apex class to update the description field of the current record.

public class test{
   public String currentRecordId {get;set;}
   public test(ApexPages.StandardController controller) {
       currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
   }
   
   public void updatecurrentrecord(){
       try {      
           Case caseToUpdate =
           [SELECT Description FROM Case
            WHERE id = :currentRecordId
            LIMIT 1];
   
           caseToUpdate.Description = 'test description';
           update caseToUpdate;
       } catch(DmlException e) {
           System.debug('An unexpected error has occurred: ' + e.getMessage());
       }  
   }
}

2. Create a VF page to display the currentrecordid and call updatecurrentrecord function from above apex class.

<apex:page standardController="Case" extensions="test" action="{!updatecurrentrecord}">
   <h2 style="background-color:rgb(255,0,0)">
       This is your new Case VF Page
       <apex:form >
            <apex:pageBlock >
               <apex:pageBlockSection title="Current case record Id is : {!currentRecordId}" collapsible="false">
               </apex:pageBlockSection>     
            </apex:pageBlock>
       </apex:form>
   </h2>
</apex:page>

 3. Add the VF page to the Case object layout.
 4. Make sure you are in Lightning Experience.
  On the View page, you will see the inline VF page generated correctly.
Screen Shot 2016-02-15 at 8.39.22 PM.png
However on the Create page, you will see the following error, because currentRecordId is null
Screen Shot 2016-02-15 at 8.47.03 PM.png
The takeaway is: always write “safe” code with error handling and empty checks. Please be aware of this change and check your existing implementations.




  • Another change for Lightning Experience is that you can no longer override standard/custom Tabs with the same object's list action. In other words, you can not override Account Tab with Account List action.

Here’s an example:
1. Create a test Apex class with the following code for redirection.

public class test {
   public test(ApexPages.StandardSetController controller) {}

   public test(ApexPages.StandardController controller) {}
   
   public PageReference init(){
       String url='/006';
       PageReference pr = new PageReference(url);
       pr.setRedirect(true);
       return pr;
   }
}

             2. Create a VF page
<apex:page standardController="Opportunity" extensions="test" recordSetVar="opportunities" action="{!init}"> </apex:page>
             3. Override Opportunity Tab with the above VF page.

             4. Switch to Lightning Experience, click on Opportunity Tab. You will see this error.

“This page isn't available in Salesforce Lightning Experience or Salesforce1.”

The reason behind this behavior is that in Lightning Experience, Object Tab and Object List actions are combined into one page. After clicking on the Opportunity Tab, you are already at the Opportunity List page. So you are not allowed to redirect to the same page again.

Interestingly, you can override Opportunity Tab with the Account List or override any other Opportunity actions with the Opportunity List action. For example, if you change the PageReference in Apex class to “/001”, clicking on the Opportunity Tab will take you to the Account List page.




Routing in Lightning Experience is different than Classic UI. Even though your implementation works in Classic, make sure you still test it out in Lightning Experience. Branch off code between Classic and Lightning Experience with sforce.one if necessary. Make sure you read through limitations of Visualforce in Lightning Experience.