Thursday, 24 December 2015

Apex Testing goodness in spring 16

Spring 16 release notes has been great read .If you have not read ,find some time and do a quick scan to discover some really cool features .

Apex Testing enhancement coming  in spring 16 caught my attention and this blog post covers them in detail .

1)Ability to set createdDate value for test data before Test.startTest()

The below test class demonstrates this new feature 

2)Test Suite

Test suites provide ability to run group of test classes together .On developer console you will find that you have ability to create a New Suite and use New Suite Run to run multiple suites or a single suite .Test Suites functionality is also available through Tooling API .I wont be surprised if this feature is added in some of IDE like Mavensmate or Welkins Suite 

The Suite Manager helps to add or remove Test classes to existing suites or form a new suite or delete existing test suites.

3)Stop a Test Run That’s Failing Miserably

You can now configure test runs to stop executing new tests after a given number of tests fail. You no longer need to waste your time waiting for the results of a run that you’re going to rerun after fixing issues in your org. You can set how many tests can fail in test runs that you execute both in the Developer Console and using the Tooling API.

The Developer Console’s test run configuration panes have a new Settings button. 
To specify how many tests can fail before a test run or test suite run is canceled, click Settings, enter a value for Number of failures allowed, and then click OK. This value applies for all test runs that you execute, until you close the Developer Console or set a new value.

I don't see this yet in spring 16 preview org and i assume it will be delivered .

4)Call Test.startTest() to Reliably Reset Limits in Apex Tests

5)Use @future to Avoid the Dreaded MIXED_DML_OPERATION Error in Apex Tests

To avoid mixed DML we used future method to separate transactions and this caused failures in test class .There are number of workarounds available 

1)We wrapped the code in future method with system.RunAs 
2)Also we  enclosed the code block that makes the future method call within Test.startTest and Test.stopTest statements.

check below link to know the workaround used before this release

All these workarounds no more needed and test class now does not throw mixed DML

Check the example documented for more details 

6)Test support for asynchronous WSDL based callouts

There is a neat example on how to approach test case for asynchronous WSDL callout in apex guide

Overall there has been great improvement in Testing framework of the apex .Test classes are very important for all apex code on platform .This needs to be seriously taken and great to see SFDC doing its best to enhance testing capabilities .

Friday, 18 December 2015

Trailhead Awesomeness Continues...

Last night I completed new modules and new project on Trailhead and I must admit Trailhead continues to impress me .Its been one of the best online training resource we have to get trained on platform .

Lets talk about what will you learn once you complete these new modules and why it is worth to spend time on these

Boost your Apex Integration Skill set

Apex Integration Services

One of the key challenge for developers who are new to the platform is they lack knowledge around art of possibility around Integration of platform with external system using apex services .One of the main cause has been lack of easy step to step guide so that they can follow and learn these techniques .

The new module Apex Integration Services is a great step forward .I was surprised how challenging these exercises are to crack and it makes sure you understand the concepts well .I strongly recommend cracking this module to gain expertise around integration via apex .

Take your ability to debug and write formulae in to next level

Advanced Admin Trail
Advanced Formulas module is amazing and worth cracking it .It took me an hour being advanced and experienced dev so if you are new this may take more time .You will write some cool validations rules and some complex formulas .After this module i am sure you will be fearless when it comes to writing or debugging some complex formulas .Also note that this is part of new Trail Advanced Admin .

Continue your lightning experience adventure with new modules LEX chatter basics and LEX data management

LEX Data Management

LEX Chatter Basics

Lightning experience is the future of salesforce .With new modules you will continue to understand how to leverage chatter in lightning experience and also understand how to import and export data via dataloader and import wizard provided in the set up menu .

Build an awesome app learning platform basics and also give yourself a chance to win Astronomical Prizes

Battle Station App

This module helps you to learn platform basics and at the end you give yourself a chance to win some cool prizes .So hurry and get this done before 31st dec .The project link is below ,click and get started.The project will teach you how to create apps ,build objects and fields on platform ,write business logic using process builder and workflows ,how to create reports and dashboards and how to use SF1 mobile app to expose the functionality for mobile devices.

Apart from these  Application Lifecycle Management module  is being rewritten to provide more awesome content .

Enjoy Trailhead and dont forget to post your selfie with badges completed on twitter .Also now you can add those badges to your linkedIn profile .

Trailhead Selfie

Sunday, 6 December 2015

IOS and Visualforce in Salesforce 1 app Hicups

Lighting is out and looks like its  the future of customization of Salesforce 1 mobile pages .Speaking of present still we have large number of apps having visualforce page for the Salesforce 1 app build using either angular(or other frameworks ) or plain old visualforce styled to responsive design .

This blogpost is sharing some insights into common issues that I encountered with Visualforce inside SF1 container when I was testing the functionality with iPhone or iPad.

Lets list all of them one by one and list the work around for issues as these have no proper fix and are logged as issues by SFDC

1)Key freezing issue with HTML input tags

This is one of the primary issues that's  really show stopper .If you have a visualforce and you use apex:input or normal HTML input and double tap the cursor on the text field you will notice that your keys are freezed and text you enter dont appear on the input box .

This looks to be serious issue with new version of IOS and Salesforce 1 app .Even you are using twitter typeahead for autocomplete or lookups this issue can be easily observed and keys will freeze once you make selection .

The workaround for this is to include a small script at the bottom of the page that resolves this .Please note this is a workaround until this is fixed officially

2)Not able to scroll the iframe embedded in Visualforce inside SF1 container for iPad or iPhone 

This is another common bug and has something to do with IOS webkit inside SF1 .The workaround is below small snippet that adds scrolling behavior needed

There are also certain things that we need to note about navigation pattern we follow in SF1 specific apps

1)When navigating to the external world the right function to use is as below

navigateToURL(​url​[, isredirect])

If you want SF1 container not to remember the history set redirect parameter to the true state.

2)Use back function to navigate to the back and use redirect parameter as true if you want your page to refresh


Using frameworks to develop SF1 apps can increase the speed of app build .Also for complex SF1 visualforce page if you have too many actions and you are packaging for as an appexchange app its worth to write some automation testing using selenium or using protractor whatever you feel comfortable just to not scratch your head if something breaks later due to SFDC releases or due to some code change during upgrade.

I hope you enjoyed this post and will help you troubleshoot issues with SF1 app

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...