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
2
votes
2answers
656 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 ...
31
votes
0answers
741 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
197 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
98 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
905 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
977 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
51 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
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 ...
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
949 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
315 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
765 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
320 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
314 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
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 ...
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
118 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
813 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
331 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
4k 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 ...
5
votes
3answers
353 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
400 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
147 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
999 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
823 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 ...
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 ...
5
votes
1answer
983 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
40 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 ...
2
votes
2answers
94 views

How to move Remoting apex to static resources

I'm developing a Managed package and just started to move some code, I noticed some of my javascript functions are exposed in the code, I would like to move all that code to static resources leaving a ...
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 ...
11
votes
1answer
481 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 ...
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 = [...
0
votes
1answer
73 views

Error Logging versus Showing Error to User

What is a better strategy when writing apex or visualforce code, with respect to error logging? Show errors occurred to end user (OR) silently log them to a custom object (OR) both of the above
0
votes
2answers
359 views

best practice for object initialization

What is the best approach from below two for initializing an object instance while creation in a loop. for(string str: stringList){ //create obj records ...
0
votes
3answers
304 views

how to to rollup the field for custom object? [closed]

i am having 1 custom object capital adjustment with a field name tax. i want to roll up this tax value to another custom object contact(i cant able to look up with the capital adjustment). please ...
0
votes
1answer
93 views

Best Practice: Formula field Vs new (duplicate) field

I have custom object with Lookup to contact and need few fields in custom object which are already present in Contact. Is it good to create formula field in custom object or create a same field and ...
0
votes
1answer
4k views

How can I display string returned by a Apex class method on VisualForce pages?

I have written the following Apex class. Now, I wish to display the string returned by getMonthsString() on VisualForce Pages. Here is the Apex class: public class MyFirstClass { public static ...