Skip to main content

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

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects_test_methods.htm

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

Check the example documented for more details

https://releasenotes.docs.salesforce.com/en-us/spring16/release-notes/rn_apex_tests.htm#rn_apex_tests_limits 

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 

https://releasenotes.docs.salesforce.com/en-us/spring16/release-notes/rn_apex_tests.htm#rn_apex_tests_limits

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 .

Popular posts from this blog

TLS 1.0 has been disabled For Sandbox - Salesforce

Salesforce has finally disabled TLS 1.0 in sandboxes .This is in preparation for disablement later in 2017 for PRODUCTION instances .

Now this would have not impacted your integrations in PRODUCTION org but if your integration is broken in your sandbox ,this means you have only few months to sort this and fix before this affects your integration for PROD live users .
Before we deep drive on how to possibly fix this and work with your external systems to figure solution ,lets first understand what is TLS and why did SFDC moved to 1.x and had to disable TLS 1.0
TLS 1.0 Explained























TLS 1.1 Improvements 
Added protection against cipher-block chaining (CBC) attacks. Support for IANA registration of parameters.

Clearly TLS 1.1 is more secure(Compared to 1.0) and protects salesforce resources against CBC attacks .
Identify if this change broke anything .The things that can be affected in your instances are as below Web requests to Salesforce URLs that require authenticationWeb requests to the login pag…

Opening Modal Using Lightning Component Framework of SFDC

One of my friend from India threw a challenge .The challenge was to open a modal by using latest and greatest lightning components framework and modals design from SLDS .For the love of community I thought of sharing the entire code base that I did .

So here we start ..

Business Use Case - Need a handy SalesLeader board component that can be used to display the Sales revenue generated by each sales rep for current year in the order of decreasing total revenue .On click of the tile ,we will show detail opportunity list aggregating the revenue .

The component can be dragged in lightning design experience or in App builder lightning Page .

Video Demonstration-



SalesLeaderBoard from Mohith Kumar Shrivastava on Vimeo.








Frameworks Used -
Lightning Design Systems (SLDS) for CSSLightning Component Framework for client side logicApex aura enabled class for backend logicApproach
The component hierarchy is very important to imagine or mindmap before we dig deeper- SalesLeaderMain
    -SalesLeaderBoard
    …

Invoking Apex Callout From Process Builder

Process builder is GA in Spring 15 and one of the queries I came across was around how to invoke apex callouts from Process builder .

Before process builder came we had two common approaches of calling webservice 

1)We have outbound messages as one of the Actions for workflows.This works if other party implements the WSDL that is generated once Outbound messaging is defined with appropriate end point .

2)Most of times future method invoked through triggers allowed to do apex callouts and invoke external web service provided the future method is annotated with @future(callout=true).This provides lot of flexibility and one of the best approaches .

3)Flow triggers was in BETA and this was also one of the ways we could invoke callouts provided the Flow implements process plugin .To understand in detail how to implement process plugin refer to the below example

The purpose of this blogpost is to demonstrate the new possibility of invoking apex callout through Process Builder 

I tried initi…