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
1
vote
1answer
336 views

Subscriber Key Considerations when Connecting with SFDC

My organization is currently in the beginning stages of connecting our SFDC org with Marketing Cloud. One of the discussions has been around doing a rekey of our subscribers within Marketing Cloud. I ...
1
vote
1answer
502 views

Is there a better way to loop through multiple decisions / assignments?

Within my Visual Flow, I have a currency variable with a starting amount (Amount A). There is a screen which asks the user to indicate (using checkboxes) if each of three additional amounts (B,C,D) ...
2
votes
4answers
1k views

How to test a class with no methods?

How should I write test class for class that doesn't have methods, just fields and constructor? What are best practices? public SelectOption(String value, String label) { this.value = value; ...
0
votes
1answer
209 views

Create a BaseTest class with common variables and methods

I'm trying to create a class that will act like a BaseClass for my Test classes. It must include several variables, constants and methods common to my test methods. The kicker is that Test methods ...
4
votes
1answer
114 views

Best practices to follow to organize classes/pages based on app?

Currently we have multiple applications in our client org. It's hard to identify which components like Apex Classes, Visualforce Pages, etc belong to each application unless we look into each ...
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 ...
1
vote
1answer
183 views

Does this trigger have the right approach/best practices?

I built a trigger to update account owner depending on an external id value (Salesperson). If the salesperson code exists in a user then he will be the owner, if it doesn't exists or the code it's ...
0
votes
1answer
52 views

Is this trigger bullkified?

Will this trigger work for bulk processing? trigger ContactAfterInser1t on Dr_Invite__c (before insert, before update) { list<Dr_Invite__c> aList = new list<Dr_Invite__c>(); Set&...
6
votes
1answer
224 views

Bad practice to have unused trigger events in Apex trigger

I am curious if it's bad practice to have unused trigger events in your trigger signature if they're never run. For example trigger SampleTrigger on Account (before insert, after delete) { if(...
2
votes
2answers
728 views

rest apex security best practices

We've have created plenty of REST Apex classes and access them using OAuth 2.0 using Web Server Flow (consumer secret, consumer key, etc.) However, we're in the process of creating our first REST ...
33
votes
1answer
809 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 ...
1
vote
1answer
221 views

When merging Master Object, how to make ensure child objects are merged as well? (if possible)

In our Org, we are using Person Accounts; so Joe Smith can have preferences, for example he only wants red cars when renting. There's a duplicate Person, Joseph Smith, who of course only wants red ...
2
votes
2answers
105 views

Best Practice for testing with RunAs method

I noticed that when you create a user in a test class that the username must be unique in the real production environment. Most of my test classes are creating a user to then run the test method as. ...
1
vote
1answer
1k views

Trigger inserting master/detail objects

What is the best way or practice to insert two different fields value in two object which are master/detail using Triggers? Employee__c: Employee_Id Hire_Date Start_Date Emp_Detail__c: Employee__c ...
-5
votes
1answer
2k views

Salesforce coding standards and Best practices [duplicate]

Can somebody share any documents OR links which is related to Salesforce coding standards and Best practices to follow for development.
3
votes
1answer
1k views

Best Practice while using Test.startTest & Test.stopTest in Test class

Can someone please let me know when exactly Test.startTest & Test.stopTest can be used? Can I use it always in my Test Class as a Best Practice while doing a DML to get a separate context and ...
0
votes
0answers
57 views

Time-Dependant Workflow workaround for ContentVersion

What's the best way to mimic a time-dependant workflow for objects (in this case ContentVersion) that don't allow Workflows. I've considered Scheduled Apex but am concerned about limits.
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 ...
3
votes
2answers
2k views

Code Optimization

is there a way to optimized this code? I am having problem with bulk upload and these needs to be optimized, can you instruct me on what should be the proper way? I'm getting System.LimitException: ...
17
votes
2answers
471 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 ...
0
votes
3answers
48 views

Move update out of loop and use system method

I have a simple trigger to update standard Account field from custom field (b/c of Lead conversion mapping limitations). I want to move the update out of the loop and use a database.update(newAccount,...
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 ...
5
votes
2answers
1k views

Trigger Best Practices - Updating Multiple Related Objects

I have a question relating to the best practices when coding a trigger. I have already read up a fair bit on the best practices and understand the one trigger per object pattern, as well as the ...
12
votes
2answers
1k 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, ...
3
votes
2answers
359 views

Check isEmpty OR Catch ListException?

My basic question is if it is better to use a try/catch block or an isEmpty check when returning the first element in a list. For example: return myList.isEmpty() ? null : myList[0]; // OR try { ...
3
votes
2answers
802 views

Is it advisable to have two Form in one VF page?

I have a Question , whether having two separate Forms in one VF page is a Best practice. Please provide your Suggestions.
1
vote
2answers
3k views

SObject Numeric field - Integer.valueOf() vs casting

When working in Apex it is not uncommon for us to work with a numeric field that has a 0 scale. To use that with some built in functions we need to use an Integer. To provide an example, let's say we ...
2
votes
3answers
3k views

Best practice for apex code to create XML that matches WSDL/XSD

Is there a commonly agreed upon best practice approach for how to generate XML in Apex that will adhere to the WSDL/XSD of an outbound service? I've so far only encountered code that does a manual ...
0
votes
1answer
2k views

What use cases warrant multiple business units?

Is there a litmus test for when multiple business units become the best practice for a Marketing Cloud implementation? In the official documentation, I've seen the primary benefits discussing user ...
3
votes
2answers
339 views

Best Practice Q: Should our sales staff be allowed to delete Opportunities?

Context: I am an Engineer looking to create a 1-1 relationship between SFDC.Accounts and our own "customer accounts" in our internal system. Question: During implementation, we have discovered that ...
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 ...
3
votes
1answer
372 views

Bulkification of SingleEmailMessage

I'm trying to bulkify my code, and send all emails out as part of a list however I'm receiving the following error; Method does not exist or incorrect signature: [List].setTargetObjectId(Id) What ...
2
votes
1answer
1k views

Exposing apex class for both SOAP and REST API

I read this post and learned that same class can be used to exposed for consuming SOAP and REST API: Exposing same apex method via SOAP and REST API? My question is: Which of the below is the ...
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 ...
10
votes
3answers
4k 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 ...
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 ...
1
vote
2answers
131 views

Does scheduler instantiates second batch even if first batch is not finished yet?

I have a quick question for which I could not find any answer in the salesforce documentation. Suppose I have a scheduled job which invokes batch job every hour. If it invoked one batch at 10AM, ...
2
votes
2answers
864 views

Using Custom Settings in Apex Trigger to Call Different Values for Sandbox/Production

I have an Apex Trigger for a Salesforce integration that looks like this in the Sandbox environment: trigger Trigger_5074086a_493f_48d2_a8fd on Opportunity (after insert, after update, after delete, ...
2
votes
0answers
340 views

Generating subscriber keys

We have a master list of over 600,000 records in Marketing Cloud (ExactTarget) that was not set up with a Subscriber Key. As we're planning on using SMS for some subscribers, we need to set up a ...
5
votes
1answer
5k views

One Process Builder vs Multiple per single Object

I've read somewhere about an idea of implementing all Process Builders that are executing on a single object within a single Process Builder, instead of using multiple ones (IMO this is a similar ...
6
votes
3answers
423 views

SOQL Style Guidelnes - Large SELECT Clause

I have a long SOQL query with a lot of fields in the SELECT clause and conditions in the where clause. How do you write it, so it's stylistically sound? I get that this is subjective...
0
votes
1answer
404 views

Global variable vs class variable [closed]

I have been using a global variable such as $UserInfo.getUiThemeDisplayed in a visualforce page several times for rendered conditions. In this case which is better, using a class variable or global ...
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 ...
4
votes
2answers
149 views

Visualforce Remoting Correct Approach?

I have a controller with the below (sanitized) methods: @remoteAction global static String getParam1(String someInput1){ String param1 = someInput1; return param1; } @remoteAction global ...
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 ...
2
votes
1answer
909 views

Call sendEmail method inside a loop?

Is it advisable to use sendEmail() method inside a for loop? Does it perform any DML Operations that could probably hit my SOQL limits?
2
votes
1answer
30 views

Is disabling all user accounts during a change set a good practice?

Just wanted to know under what circumstances you would need to disable all users during a change-set in Salesforce. Some of my colleagues are for it and some against the idea as you risk locking the ...
68
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 ...
5
votes
1answer
1k views

why we are create handler class of trigger in salesforce?

If we can create trigger and we can write all code in trigger so why we need to create handler class of trigger?
1
vote
2answers
41 views

Best solution to process changes to a collection based on multiple criteria in triggers?

In a BeforeUpdate trigger of a custom object, I am checking to see what custom fields have been updated and based on the updates, want to call specific methods that use the updated fields to run some ...

1 2 3 4 5 7