Top Salesforce Development Mistakes and How to Avoid Them
Many organizations have been increasingly using the services of Salesforce for a plethora of benefits. The platform provides the ability to build personalized business solutions with tons of capabilities out of the box and allows for virtually endless customization & innovation.
Salesforce’s declarative development opportunities made the software creation process easier on the companies’ IT departments. Through a combination of drag-and-drop user interfaces and form builders, the vendor enables citizen developers to build a working app and start using it in hours.
However, many businesses are looking for customizations beyond the scope of what declarative tools offer in a bid to meet their more specific requirements. At this point, the need for custom code rises. The developers inexperienced in building software in the cloud can face problems.
For those who can learn from mistakes and want to understand the Salesforce environment better, we have compiled the list of the top mistakes made by developers and proven ways to avoid them.
Mistake 1. Using traditional development methodologies
Some programmers apply the waterfall method, the most traditional approach, others prefer rapid application development (RAD), and the thirds choose lean development for their projects. Each one has its own pros & cons and works effectively in different situations.
The point is that classical software development processes don’t work similarly well for cloud-based projects. Salesforce & Force.com are cloud environments that require a different method of building applications. The vendor offers pre-built components that enable creating prototypes, developing software, and performing tests in very rapid cycles. The activities and steps used in traditional approaches are either performed differently or are needless in the cloud platform.
How to avoid: Take time to learn ins & outs of Force.com
Understanding the peculiarities of the PaaS environment and its difference from traditional tools is critical to succeed and harness the power of the platform. While your development methods may still work for your cloud-based project, they may increase the time of building software. Sound knowledge of Force.com is imperative for those looking to maximize ROI and take advantage of the platform’s numerous capabilities.
Mistake 2. Prioritizing custom code over declarative development tools
A faster turnaround time of app creation is one of the innumerable Salesforce benefits. However, this advantage can turn into a challenge for developers who get accustomed to building a solution through custom programming
They will have plenty of opportunities for coding something out to create a robust application, but why waste time and effort when Force.com performs much of the work for you. It’s always the best approach to look into using drag-and-drop functionality and services for business process automation and data modeling that could replace the need for a fully custom solution.
How to avoid: Learn when the declarative tools are the best choice
Before initiating any custom development, invest time in discovering the Force.com configuration options such as formula fields, workflows, etc. There is no reason for creating the functionality via hand programming if you can build it in a few clicks using declarative tools. Knowing the nuances of the platform features and services, and when their usage is more efficient than custom coding will improve productivity, save precious time and money. Furthermore, Salesforce provides a helpful learning experience platform – Trailhead. It combines a library of educational content and a playground for hands-on experience, letting developers learn and put their skills to the test.
Mistake 3. Writing test cases for the sake of covering code
Salesforce indeed requires achieving a minimum of 75% of code coverage with unit test cases. Since this figure refers only to test coverage, developers often disregard the quality of tests pursuing to reach the mandatory threshold.
Salesforce is a multi-tenant environment that hosts thousands of companies’ apps on the same physical platform. Any code that slows down the system affects the user experience for all users as a whole. Therefore, the vendor imposed the code coverage requirement for deploying custom Apex code as one of the indicators of the test effectiveness.
The primary purpose of the test cases is to catch logic flaws, uncover bugs, and ensure your custom code runs correctly. Forcing 75% coverage encourages programmers to double-check their work. Admittedly, you can write useless unit tests, but the more branches of code you cover, the higher probability of finding a regression bug if you change it later. Most developers acknowledge that unit testing is crucial for the maintenance of a code base and Continuous Integration.
It may seem like a chore, yet there are some tools and techniques developers use to simplify the process and secure the efficient code functioning within normal parameters.
How to improve the testing procedure
- Defining a clear perspective of the customizable features will help you concentrate on your custom code alone in place of testing built-in Salesforce functionality.
- Using test automation tools is a proven way to increase the consistency of code testing while reducing time. Apex Unit is a testing framework aimed to streamline the management of unit tests. This framework allows you to schedule and run tests asynchronously as well as filter and group tests into suites. The tool helps with code coverage requirements by providing metrics and test reports.
Apex unit tests are great, but it wouldn’t be enough to ensure that your code is working end-to-end. You have to employ automated tools to test your application from the perspective of UI, functionality, integration, and regression testing. We suggest using these most widely used tools for web page testing:
- Selenium Webdriver – for browser-based UI testing
- HP Unified Functional Testing (UFT)
Mistake 4. Following general design guidelines
Visualforce allows developing a rich UI with complex multimedia or deep interactions. Salesforce developers can’t resist using these abilities to create dynamic custom interfaces. However, first, they forget about the enormous capabilities of the platform aimed to streamline the process. Second, they risk reaching the limits for page sizes and facing performance issues.
Code reuse in Visualforce is essential, especially in large projects, where many developers might try to reinvent the wheel by writing the same markup and logic over and over or copy-pasting the Visualforce code across different pages. This amateur activity leads to a maintenance hell in the long-term for sure. The good news is that this issue is easy to address with the help of the platform’s components.
How to avoid:
1. Check the tools available on Salesforce
There is an online tool Visualforce Generator that makes an autogeneration of the VF page layout as easy as just a button click. Further, you can modify it as per your requirements. You even don’t need to install anything.
2. Don’t overload the page with data
Pages overloaded with functionality and unbounded data is a bad practice that can lead to poor performance or ability. You must design a VF page around the particular task with defined workflows and navigation. Pushing back on requests to add non-essential functionality enables adding features without impacting performance. All-in-all, building prototypes is an excellent way to validate the concerns. With Force.com, prototyping the core concepts of your software will take no more than several days.
3. Reuse custom code
Visualforce is a framework that enables the design of dynamic UIs with the help of custom controllers and components, which you can reuse for creating other pages. There are multiple ways of achieving code reusability within VF pages.
- Referencing an existing page. It’s the basic technique of code reuse designed to insert the entire content of a VF page into another.
- Creating templates or page layouts. It’s a more sophisticated template-based approach used to follow a general layout pattern across different pages.
- Defining custom VF components. This technique is the most flexible because custom components allow you to encapsulate design patterns and reuse them for n-number of times in multiple pages.
The platform offers superb components that make code reuse painless and the design of interfaces faster. It’s especially important when you work on medium or large projects.
Mistake 5. Running into governor limits
Since the development lifecycle is rapid in Force.com, programmers are typically diving into building one custom solution after another.
But that day happens when you get the governor limit error message. Upon research from this error, you find out about the limits, which are established by the Salesforce to assure the practical usage of resources and code effectiveness. There are a lot of constraints that restrict standard code implementation to ensure that no one acquires resources from others. The vendor has to do this because of its multi-tenant architecture, where every organization shares the same resource.
So, when first using the platform, you are most likely to encounter the governor limits such as:
A. SOQL query limit
You may hit this limit by doing too many SOQL queries per transaction or in case you perform a very long query that fetches a lot of data. On top of that, there is the character limitation for SOQL statements that contain many formula fields and restrictions for query runtime. You can exceed these limitations by adding very many currency fields that require SOQL to use a format method, merely doubling the field API name length. Upgrading your subscription will not increase your limits. The only workaround is to understand how to navigate around them.
B. Not bulkifying your code
I am quite sure you have heard the phrase “Bulkify your code” a lot, but what does it mean and why this one is important. Bulkification is termed as the ideal way of writing code. This method refers to a combination of repetitive tasks in Apex so that your code correctly handles multiple records at a time. The fundamental idea behind this practice is to optimize your code to ensure the appropriate work of the features, and high performance of your triggers within platform limits. Not paying attention to this concept may impact performance or sometimes lead to a complete code rewrite.
C. Creating several triggers on one object
Many triggers on a single object will confuse the system. The order of execution can’t be defined when having many triggers for the same object due to the same event. The Salesforce system will be unable to connect the flow of all the triggers and execute them synchronously. If you cannot specify the order that they will run in, then you may have unpredictable outcomes.
How to avoid: Optimize code
Even the most advanced design will need code optimization due to runtime constraints. Following these proven techniques will help you to create high-quality code that doesn’t violate limits:
A. Never do queries in loops
When writing a SOQL query inside a for loop structure, your code runs slowly, and triggers are guaranteed to hit governor limits.
The secure method of writing the trigger is to take the query out of the loop structure. To achieve this, create a set object to collect the necessary data and loop through the collection of triggered records. Then create a map object to store a combination of data and user objects. It adds some complications, but this strategy helps to get around the query limits.
B. Make your code bulky
In all your coding, minimize the number of times you touch the database to read or write records. Every code that runs queries must do it in a bulk way. The same rule refers to utility methods and helpers that an Apex request executes. We would suggest using bulk design patterns for records processing. They help make your triggers less resource consuming and efficient enough to handle bulk records. Bulkification of your Apex code is the key to make sure it runs smoothly.
C. One trigger per object
Develop a single trigger which will invoke various Apex classes to do the actual work. If you found out that you have more than one trigger for the same event, it’s better to combine them. Otherwise, you will not be able to control the order of execution. Hence, your code will be unpredictable.
Here you can find the full list of governor limits every Salesforce developer must always bear in mind.
We hope this blog post will help you avoid the mistakes many developers find themselves in. Salesforce is a robust, cloud environment that provides a high level of flexibility to develop software while maintaining enterprise-level security & privacy. Declarative tools & built-in features of Force.com enable building SaaS apps faster than ever. Instead of struggling with thousands of lines of code, it would be better to focus on the business entirely. Mapping the platform capabilities to your business needs is pivotal for success in the cloud.
Have trouble developing your first Salesforce app?
If your business is facing a bottleneck problem that you can’t overcome on your own building or deploying your business application in Salesforce, contact us to get expert recommendations on your issues. ApexTech team of certified Salesforce professionals will help you make the most out of your investment.