The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [bestpractice]

Referring to the use of recognized community and platform best practices. May relate to all areas of lifecycle and all development and administration activities.

Filter by
Sorted by
Tagged with
66
votes
5answers
9k views

Pokemon Catch - Generic Exception Handling In Apex

I read a great post about this topic on Stack Overflow: Is it really that bad to catch a general exception? However, I asked this question on our exchange because I am interested in a more specific ...
64
votes
6answers
17k views

What is a good set of naming conventions to use when developing on the Force.com platform?

I've looked in the Apex developer's guide and a saw the Naming Conventions section which has basically only has this: We recommend following Java standards for naming, that is, classes start with a ...
48
votes
3answers
11k views

General trigger bulkification - best practices

A general question asked from time to time on stack exchange is question of trigger bulkification. Therefore I have 2 questions: Which best practices are you using? What is the best way to handle ...
41
votes
4answers
1k views

Why Are Data Silos Important in Unit Tests?

I have a lot of strong opinions about this issue, but had a hard time finding official documents today to back up my position. A lot of times we say it is bad practice to use seeAllData=true, but we ...
36
votes
2answers
2k views

Why Would I Not Enable Chaining?

The Apex Design Patterns is an awesome resource, and I learned many tricks from it. One of my favorites is method chaining, and I quickly developed an axiom: Any time you would return void, return ...
36
votes
3answers
6k views

How to use GIT on multi dev environment

I have previous experience using GIT in other development environment and I never had much troubles using it. We where using SVN for salesforce, however we want to migrate to GIT for the uncountable ...
34
votes
6answers
5k views

What is a good set of coding conventions for Salesforce development?

I've looked around in the Apex and Visualforce developer guides and around the web and can't seem to find any coding conventions out there. The Apex Dev guide has a section on Naming Conventions that ...
34
votes
2answers
6k views

When To Use Set vs. List In SOQL

I have always assumed that it is better to use a Set in my query filters instead of a List. For example: Set<Id> parentIds = generateParentIds(); List<Child__c> children = [SELECT Id FROM ...
34
votes
1answer
25k views

Writing Test Classes for Apex RestService

I was writing test classes for my apex Rest Service that i had built for an ipad app. I noted very interesting things while experimenting.Before anything i just did a google and found an interesting ...
32
votes
1answer
2k views

Does an Apex or VisualForce code style guide exist?

Has anyone written an Apex or VisualForce code style guide, in the way of the Ruby Style Guide or jslint, or PEP-8, or any number of Java guides? I'm in the process on creating one for internal use ...
31
votes
8answers
9k views

Use of @IsTest versus testMethod and location of test methods in classes

Is there any advantage to using the older testMethod keyword to identify test methods or is it better to use the @IsTest annotation? Does the location of these test methods have any significance? E.g....
31
votes
2answers
12k views

Post Sandbox Refresh Steps

What steps should be taken after a sandbox refresh to avoid filling up the sandbox storage, sending emails, or outbound messages? I'm looking for steps to take such as disable scheduled Apex jobs, ...
31
votes
0answers
731 views

Best practices for designing and maintaining Global classes?

We've always been conservative when it comes to exposing Globals for use by extension packages or subscriber extensions, and perhaps too conservative. We're considering being more proactive wth our ...
28
votes
2answers
8k views

How to set up views and navigation in Lightning?

What is the best way to create views in Lightning? And then, how would you navigate from one view to another? Conceptually I'm thinking that I'll have two components, ns:foo and ns:bar, and ...
24
votes
2answers
8k views

Which one is better : Loop with SOQL or create a List then Loop?

Some of code I read in trigger is like this for(account a: [select id from account where id in: mapAccount.keySet()]) { //code } some are like List<Account> listAccount = [...
21
votes
2answers
438 views

Friction-free process to switch to SalesforceDX with existing managed package

Dreamforce '17 made it crystal clear. Salesforce DX is ready for prime time. With Second-Generating Packaging SGP even for ISVs. Salesforce DX is awesome, nonetheless we fear that getting started ...
20
votes
3answers
21k views

Best practice for calling Apex methods from custom button?

I want to put a custom button on a standard detail page layout to execute Apex code, and I'm wondering if using VF page action attribute is the best practice. Here are the details. When the user ...
18
votes
4answers
13k views

Efficiency of List.size() > 0 vs. !List.isEmpty()

Anyone have any data to support a claim for which of the following two expressions is more efficient (meaning faster)? The use case is determining whether a List is empty to inform an auxiliary method ...
18
votes
1answer
4k views

Best Practices for Managing Org Profiles & Permissions

Are there any books, tutorials or whitepapers out there that recommend a strategy how to cope with the complexity of profiles and permissions in big Salesforce orgs? You find fragments of that in ...
17
votes
7answers
363 views

How can I build an app for a company that has two very distinct types of customers?

I am working on building an app for a startup company on the Force.com platform, and I am struggling to find the best way to set up and distinguish between two very distinct customer types. The ...
17
votes
2answers
447 views

Visualforce PageReference - Name Constructor vs. Factory

For a developer who wants to use a PageReference to redirect to a Visualforce Page, are there any notable differences between constructing it by name versus using the Page.PageName factory method? By ...
15
votes
3answers
1k views

Best practice with big classes Apex

We've got this recommendation from Salesforce after an audit Class Complexity: • Refactor complex classes and methods into more manageable classes. Consider the use of Process Builder to ...
15
votes
4answers
7k views

How to avoid instantiating object inside a loop?

There are many scenarios where I have to create records of polymorphic objects using apex. For e.g. creating a Task record or a CustomObject__c record for each Case created. In general I do something ...
15
votes
2answers
18k views

How to pass values across Lightning components?

What is the best way to pass, propagate or share values across Lightning components? For example, let's say I have two components ns:foo and ns:bar. Both components have the following attribute: <...
15
votes
3answers
6k views

apex:include vs. Visualforce component, when and why?

I recently had a reason to look more closely at the standard apex:include component in Visualforce, and I'm intrigued by the intent behind this component. Would anyone be willing to share some ...
14
votes
4answers
4k views

What are Apex Performance Best Practices?

Is there a definitive guide somewhere that outlines the best practices for faster executing code? I am looking for specifics, like Adding elements to a Set versus to a Map Testing for null before ...
14
votes
3answers
10k views

How to avoid recursive trigger other than the classic 'class w/ static variable' pattern?

How can we avoid trigger get executed again and again (recursive trigger)? One way is to have a class with static variable and have boolean value and check it is true or false and changing the boolean ...
14
votes
2answers
3k views

What is the difference between (Id)str and Id.valueOf(str)?

Say I have one string String strId = 001xa000003DIlo and I want to typecast it to an Id. So I have two options to do so: Id idVal = (Id)strId; Id idVal = Id.valueOf(strId); Which is the best way to ...
14
votes
4answers
2k views

Lightning Framework vs Standard Client Side Frameworks (i.e. React) // Which to chose when, and why?

Disclaimer Keep it objective! This one can get a little opinionated, please try to keep your answer specific to the facts a developer should be considering when choosing between two viable options ...
14
votes
1answer
790 views

Consolidate trigger methods or not?

I have a general best practices question about triggers. I have created a handful of triggers that perform different actions but are called by the same event, such as after account update/insert/...
13
votes
4answers
2k views

Archiving Data to Heroku

Ok after hours of searching I cannot believe that something that would seem like an every day need does not have any videos, tutorials, etc directly related to it. Heroku is tough for me as it seems ...
12
votes
2answers
936 views

Performance Impact of DescribeSObjects vs. Individual Describe Calls?

I've been wondering this for a while, so it's time to put this question out there. How does Schema.describeSObjects perform when compared to individual calls to SObjectType.getDescribe? For example, ...
11
votes
1answer
479 views

Obtaining Single Record - SOQL vs. Instantiating New Object

Background I have a custom object which has a master/detail relationship to Opportunities. Whenever a record on this custom object is created or edited, I need to update the parent opportunity (and ...
11
votes
1answer
1k views

What's In A Hash Collision?

When I have used Custom Types in Map Keys and Sets, I generally follow a similar pattern listed in the Apex Developer Guide: public Integer hashCode() { return (31 * x) ^ y; } Someone asked ...
11
votes
2answers
428 views

Apex Modular Programming

I have a big Apex controller of a visual force page ,2500 lines of code, so i m wondering how can i separate implemented features in different module according to the topic. DealRowEdit(Apex ...
10
votes
3answers
3k views

When is it appropriate to use the @TestVisible Annotation

So from the docs I understand that @TestVisible is used to allow Unit Tests access to private and protected methods. What I was wondering is, when is it appropriate to use this annotation? For ...
10
votes
4answers
12k views

Number field without comma (thousands separator)

What is the Best Practice to display number field without a thousands separator (comma or period, depending on locale)? I have rejected the following ideas: Text field, because I have to write ...
10
votes
4answers
2k views

One Trigger Approach: Any Logic in Trigger?

I am getting my head around really using a single trigger approach and I appreciate that minimal logic should be in the trigger. I'm already using utility classes but I'm used to including filtering ...
10
votes
3answers
397 views

Apex Language question

Can a beginner learn APEX without learning JAVA. at my org I work as a administrator but the boss would like me to perform some developer duties. I have been working on a trigger and the thing I ...
10
votes
1answer
6k views

Spring 13 Test methods must be in test classes Error

Is someone getting the error "Test methods must be in test classes" I am using @Istest annotation inside the class: public class someclass{ @istest public static void testme(){ ... } ...
10
votes
3answers
908 views

Checking 'Correct' Previous value method in Trigger design best practice

One of the most common questions on this forum is around trigger recursion. There are a few standard ways to prevent recursion. My method of choice when it comes to checking for field changes, is ...
10
votes
2answers
985 views

Reliable SOAP webservice callout

Problem I have to build a reliable integration. This means that external callouts should be delivered even if the remote SOAP webservice is down. (when the ws is online) The idea is to keep the ...
9
votes
2answers
966 views

How to Reduce Repeated If/Else Logic in Code

I'm relatively new to Apex, and one thing I've found is there are a few places in my code where the same the same if/else logic is repeated. I.e. if (first_condition) { // do something } else if (...
9
votes
3answers
2k views

Is it good practice to initialize variable?

In the below class, I have a Map which I intend to use later in some function. Is it good practice that I intialize the Map with new Map(); or since it will get a value later when the method is ...
9
votes
1answer
1k views

Test Classes to Cover Multiple Triggers/Classes, or 1-to-1?

Background: My org has reached almost 750 unique un-managed classes and triggers. Until now, we had been adhering to the 1:1 test class to class school of thought. Now, we are at the point where we ...
9
votes
1answer
1k views

Is a TDD approach feasable on Force.com?

I recently tried to do TDD (test driven development) on Force.com and hit a limit that seems to contradict my understanding of how Salesforce.com wants us as developers to work. What I just did was ...
9
votes
3answers
6k views

What controls the 'severity' of ApexPages.addMessages(exception)?

I'm trying to crystallize out some 'best practises' for Visualforce Page exception handling. I think, at a minimum, a page should look something like this: <apex:page controller="PageController"&...
8
votes
2answers
686 views

@testSetup vs DataFactory?

When testing, how/when will @TestSetup annotation be preferable to a "DataFactory"? I understand how both works, but I don't see any case where I'd rather use the @testSetup annotation. I use this ...
8
votes
4answers
2k views

Salesforce Integration + Streaming API

The Salesforce Integration Patterns workbook suggests the use of the Streaming API to give an customer service agent a real time notification of a client payment. However the Streaming API is limited ...
8
votes
2answers
440 views

First trigger: coding - best practices

This is my first production trigger and I'm just wondering if there is a more efficient way to write this code. Basically, if a campaign meets the criteria in the IF statement, I want it to create a ...