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.
However on the Create page, you will see the following error, because currentRecordId is null
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.
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;
}
}
<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.
Thanks for sharing Salesforce lightning experience post.
ReplyDelete