We’re rewarding the question askers & reputations are being recalculated! Read more.

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
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 ...
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 ...
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 ...
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 ...
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 ...
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 = [...
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 ...
3
votes
1answer
1k views

Converting/Parsing an Enumeration to a String More Generically

This is an extension of an earlier question I made. So, using the answer from the previous question I mentioned, I am able to make a generic utility that would convert/parse an Enumeration to a ...
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 ...
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 ...
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
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....
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
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 ...
6
votes
2answers
7k views

Purpose of an inner class

I've read in the Apex Workbook and the Apex Developer Guide the mention of inner classes. What is their purpose? I see in the Apex Workbook that they used private variables and setter/getter methods ...
3
votes
0answers
1k views

Best way to set up dependent picklists in Lightning

One common programming challenge I anticipate in Lightning is the need to set up dependent picklists. I've cobbled together one approach shown in this gist for setting up a dependent picklist, but I ...
37
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 ...
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 ...
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 ...
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 ...
15
votes
2answers
19k 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: <...
8
votes
1answer
215 views

Most efficient way to switch on SObjectType?

It is a bit odd we can't evaluate a switch statement directly on SObjectType, so I am trying to determine conclusively which workaround is the most efficient. Just to verify, I tried to compile this ...
5
votes
6answers
16k views

Is it advisable to call Batch from trigger

I was thinking of calling a batch class from my trigger. Is is advisable to do that? As batch will have asynchronous execution with respect to trigger.
4
votes
4answers
21k views

Calling Apex Class from Custom Button, And Then Refreshing List View

I have added a Custom Button to the List View of the Custom Object. What is the best practice of calling an Apex Class on click of the Custom Button, and refresh the List View after execution of the ...
7
votes
1answer
89 views

Ramifications Of Cross-Object Reference Just For Id?

The Problem I see this pattern often and it drives me crazy: Id accountId = someOpportunity.Account.Id; // just reference AccountId! OR List<MyObject__c> records = [SELECT ... FROM ...
4
votes
2answers
2k views

Prevent SOQL Injection in Your Code

I am stuck on the prevent SOQL injection trailhead, where I am looking to determine which portions of the code I would need to invoke escapeSingleQuotes or whitelist to enable. I've made several ...
3
votes
2answers
3k views

How do I test an apex trigger that sends an email

Trigger is: trigger emailtemplate on opportunity(after update) { List<opportunity> oList = Trigger.new; List<opportunity> nList = trigger.old; if(oList[0]....
1
vote
1answer
48 views

Best practice for a query inside a batch and Mapping

I'm working on a batch which getting a params from another batch in the finish method. The Params are : A Map - Map<Sobject,Set<String>> A Set - Set<String> I lost the values of ...
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 ...
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 ...
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 ...
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 ...
5
votes
2answers
253 views

lwc dataservice architecture best practices

While developing lwc components and lightning apps I always run into this design dilemma: When I have two children components that uses the same set of source data but in different forms what is the ...
10
votes
3answers
910 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 ...
7
votes
2answers
1k views

DOM manipulation using External libraries in lightning component

As per the LC documentation and answers to the below questions: 1.Jquery selector is not working properly in subsequent loads in lightning component. 2.DOM modification feasibility in lightning. It'...
5
votes
2answers
6k views

Best practice for catching and displaying action errors in Lightning components

There are zillion of ways to handle or ignore errors thrown from actions calls in Lightning controllers. var action = cmp.get("c.controllerMethod"); action.setCallback(this, function(response) { ...
17
votes
2answers
452 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 ...
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 ...
7
votes
1answer
1k views

Best practices for custom controller actions

Many times I've came across the following issue: should I use one custom controller for all the actions for some sObject or some area, or maybe there should be separate controllers for editing, ...
4
votes
2answers
1k views

Can I use platform event (which calls apex method) as alternative to future method?

Can I use platform event (which calls apex method) as an alternative to invoking future method from trigger? Is this against salesforce best practices?
2
votes
2answers
243 views

(Why?) Is it good for Apex classes and methods to be final? [closed]

By default, in Apex, unlike Java and other OOP languages, all classes and methods are final. You aren't allowed to make this explicit and if you want things not to be final, you need to use the ...
6
votes
2answers
3k views

What are the best practices for Triggers

My requirements are: Upon creation of Accounts there is a trigger that creates a contact with specific record type Organization Donor Proxy I wanted to create another trigger on Account after Insert/...
5
votes
2answers
1k views

Is this good coding practice?

Today I have been going through some triggers written by former consultants and it seems like they "brute force" some stuff. It may be fine that that did it this way but it seems like to me it could ...
5
votes
1answer
1k views

Is it possible to write Trigger for Before & After DML?

I'm wondering if I can write the trigger on Case, that works before and after DML in one file? I have two triggers on Case - first with method working on records before insert, and second for records ...
3
votes
1answer
361 views

Development Life Cycle of using GIT in salesforce. [duplicate]

I need guidance regarding the Development Life Cycle of using GIT in salesforce. How to test the latest code that I fetch from the GIT to eclipse. ?? What i'm upto this, is that, after syncing the ...
3
votes
3answers
157 views

Batch - Sending data from one batch to another

I having a little issue to understand the concept of passing params via batches. I have two batches which I would like to send data between them. Batch A creates a Map<sObject,Set<String>&...
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 ...
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 ...
5
votes
1answer
2k views

What is the Best Practice for the right Training Environment?

As we all know, good user trainings are crucial to ensure a high adoption rate and a successful CRM strategy. I'm hired quite regularly by customers to provide enduser trainings. Always there is the ...