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

learn more… | top users | synonyms

3
votes
1answer
31 views

Governor limit on trigger clarification

If I have a below loop: List<id> var2=new List<id>(); for(Sobject1 s:trigger.new){ var2.add(s.Sobject2); for(Sobject2 var: [select Sobject2 from Sobject where Id IN:var2){ //do something ...
1
vote
2answers
36 views

Writting efficient trigger way

I have the below piece of code: List<Job_Opening_Skill_Set__c> jobopening= [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]; Map<Id, ...
1
vote
2answers
44 views

Too Many SOQL Queries: 101 - trigger

I am getting error message and I believe it to be error with this trigger. I am new to coding and this was done previously so any assistance is greatly appreciated trigger setAttendeeNumbers on ...
24
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 ...
2
votes
1answer
39 views

AggregateResult Use Case Best Practice

Trying to determine best scenarios for using AggregateResult e.g. Versus using a for loop gathering totals with += or similar syntax.
0
votes
0answers
20 views

Best Practices for Salesforce [duplicate]

I am new to salesforce,i am from java background. Could you please guide me where can i find best practices for writing apex,batch,triggers I have already gone through David Liu tutorials. I am ...
6
votes
1answer
87 views

What is a good and free static apex code review plugin for IDEA, eclipse and ANT?

Java has a number of useful and FREE tools for reviewing not just formatting and style but quality of code and bad coding habits. Checkmarx and Code scan could work but they are not free and open ...
3
votes
1answer
58 views

Querying / Managing Queries with Multiple Permutations

I'm writing a class to implement Support.EmailTemplateSelector. To retrieve the correct email template, I'm querying a Custom Metadata Type Smart_Template_Loader_Conf__mdt, retrieving an ...
5
votes
3answers
95 views

Trigger bulkification when adding errors

Snippet 1: trigger AccountValidationTrigger on Account(before update){ for(Account accObj: Trigger.new){ if(accObj.Some_Flag__c != TRUE){ accObj.addError('Some flag should be ...
1
vote
1answer
44 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 ...
1
vote
1answer
28 views

Modeling Abandoned Cart on Orders or Opportunities [closed]

I'd like to begin modeling abandoned carts inside our org. We can reliably push in data from the cart on our ecommerce platform at various stages throughout the checkout process, email the customer ...
21
votes
2answers
297 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 ...
5
votes
6answers
249 views

Is it a good practice to skip queries with empty conditions?

I am wondering if it's a good practice to skip queries when there's nothing in 'where' clause, especially in triggers. Like: if (idList.size() > 0) res = [select id from Case where id in ...
0
votes
1answer
34 views

System.LimitException: Too many SOQL queries: 101 & CPU time exceeded

I am getting the following two errors in various scenarios of running an apex class 1) Too many SOQL queries 2) CPU time exceeded The following is the only method in my controller class for ...
3
votes
4answers
119 views

Best Practice for Sending Emails via Apex

I'm playing around in my Dev org and am using a trigger to send a basic e-mail to System Admins when an account is created as follows: private static void doNotifyAdmin(List<Account> acc) { ...
1
vote
1answer
60 views

Best Practices for generating large XML files

I currently have some requirements for an integration that I am doing and was curious if anyone had some feedback on the best initial approach. I am currently working on building out the structure ...
0
votes
2answers
32 views

Best practices for bulk updating old data

I have a new trigger that fires whenever I add/update a Contact. Let's say it calls a method in class which sets the Contact's X1337_Name__c field to a l33t h4X0r3d (that is, 'leet haxored') version ...
7
votes
1answer
135 views

Best Practice: Refresh Cadence

Background We have a fairly straightforward org structure: Our Stage environment is a Full Sandbox. All sandboxes downstream of that are Developer Pro. We added the SubDev sandboxes very recently ...
2
votes
2answers
84 views

Avoid Multiple Triggers in Managed Object

Is there any official best practice, approach, recommendation, solution, work around, etc. for the scenario were we would want to extend a managed trigger actions? This topic has been discuss in some ...
0
votes
1answer
25 views

Formula for Picklist with If Conditions

I have 1 pick-list called Ward Types. Ward Type items are, Suite Deluxe Special AC Semi Private General Ward I want the formula for if(WardType__c == 'Suite') { Amount__c = 500; } ...
1
vote
1answer
29 views

How to handle multiple input/output tags with the same fields in VisualForce

I have created a VisualForce page that is basically a wall of inputFields. I had a requirement to make all of the inputFields into outputFields when a certain event happens (the event happens, all ...
3
votes
2answers
238 views

Is this an abuse of ternary operator and inline SOQL or is this acceptable?

I have written a function like the one below to check if there is atleast one occurrence of a given Id in either of the two objects. I am having doubts on if I should use an if branch or use a ternary ...
2
votes
2answers
43 views

Best practice for testing VF/Apex around Reports is (SeeAllData=True) + actual reports?

Here I thought the new Analytics API actually allowed us to create reports from scratch using apex. Guess not. I have a VF page and a controller extension that interacts with reports and their data ...
1
vote
0answers
44 views

Best practice for custom fields added to standard objects in Managed Package

We have a requirement wherein we need to have certain custom attributes in the Account object within our Managed Package being deployed onto an existing SFDC set up. These attributes are readable and ...
0
votes
1answer
51 views

Use IF vs Else If Statements

I have the following code (which works just fine) but am curious as to the structure of it regarding my If statements. I suppose I could be using IF-Else Statements but am not sure why that would be ...
0
votes
2answers
174 views

Test class coverage issue?

I had written test class for below apex class, but still it's showing 66% coverage. in the apex class public String[] LeadItems { method get method is covered, but set is not covered? How to ...
4
votes
2answers
209 views

Avoid Hardcoding Of UserId's in Apex

In one of the triggers, they have hard coded the userid, as below. How can we avoid this? if(currentUser != '012300000012345PPPP' && Utils.isS == false) { //DO ...
0
votes
2answers
28 views

Account field clean up best practice - how long to hold onto field before delete

We are in the process of cleaning up unused fields (generally under a 5% usage) in Accounts. The fields have been removed from the new Layouts and we are ready to deploy. How long should we hold ...
7
votes
1answer
206 views

Apex Testing Chaos

I did a "Run All Tests" in production instance and found out that the following. a) Code coverage of all the classes is 76 % b) 160 Test class failures are shown (101 from apex test classes and the ...
0
votes
1answer
63 views

Best practices for schedulable class

I have a custom object called Lease_Reminder. The object has a couple of fields on it, including Status_Alert and Effective_Date. As today gets closer to the Effective_Date, the Status_Alert needs ...
1
vote
2answers
68 views

What is the best practice when creating enterprise custom apps?

We are new to Salesforce and only recently we started actually discussing using Salesforce to support some of our more complex business operations. The use of Salesforce to support these business ...
1
vote
2answers
74 views

Login Security for Integrated Applications

Let's say you have a system that you want to integrate with Salesforce. You create a new user for the system, set up a trusted ip range, make the profile an API-only user, and then give the username ...
0
votes
4answers
891 views

Updating a field with a value from parent during insert trigger

I would appreciate some best practice advice here - I have an insert trigger to populate a field in the record being inserted into a custom object with the value of a field in the parent object. ...
4
votes
1answer
136 views

Bulk data API: How to Avoid Upserts

I'm working on an daily integration of about 5 million records (file delta's is not an option). Best practices for large data volumes recommends avoiding upserts. The only alternative solution I can ...
5
votes
2answers
162 views

Apex trigger - is this the best approach?

I'm getting up to speed with Apex - I have written a trigger that works, but is this the approach that an experienced coder would take? I have a custom object (vist_detail__c) which has a lookup to ...
1
vote
1answer
370 views

Retrieving & Updating record related by Junction Object with single SOQL query

I've written the below Trigger to update Opportunities with a date value from MPM4_BASE__Milestone1_Project__crecords. The two objects have a many to many relationship and are related by ...
0
votes
1answer
273 views

Exacttarget - Sending email to filters VS sending email to filtered data extension

I would like to send emails to a group of subscribers. I would like to filter them from the data extension subscriver_all, where all my subscribers are. From what I know there are two ways of doing ...
10
votes
4answers
345 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 ...
3
votes
1answer
100 views

Javascript Remoting vs Consuming Web Service

I am accessing a service side function through a javascript button on a visualforce page and I wanted to know; what is a better solution - Javascript Remoting or the AJAX toolkit (consuming a web ...
3
votes
2answers
49 views

How to limit control flow during unit test?

I want to limit the control flow during a unit test so that it does not leave the method being tested. The unit test is for a controller method, and in that method the controller creates an object and ...
2
votes
3answers
679 views

How to test apex code that is driven by formula fields (Best Practice)?

Question Are there any best practices out there for testing apex code that is driven by formula fields so that changes to the formula field formula don't break your test? Background Good test ...
1
vote
1answer
91 views

How to deal with Activities in a Case Hierarchy?

Let's consider a Case in the service sense of the word - a caller calls up with a situation ("My printer's broken."). Now, maybe the caller calls up about more than one situation ("My printer's ...
6
votes
1answer
273 views

Salesforce - business logic - best practices

I would be really grateful if anybody could help me clarify, where to deploy business logic. I'm aware of the following possibilities: Write the main parts of the business logic in Apex Apex ...
-1
votes
1answer
1k views

How to Write a Test Class for Webservice Class?

Situation I wrote a web service class. From my understanding unit tests in salesforce are supposed to test the whole functionality (end to end). But I don't know how to test this external interface. ...
8
votes
1answer
320 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
3answers
257 views

Should member variables be initialized inline or in the constructor?

Is there or should there be a hard and fast rule for whether to initialize a class's member variables inline vs. inside a constructor? Consider the following two approaches that I think are ...
7
votes
1answer
239 views

Considerations for calling out to enterprise applications behind a firewall from salesforce?

If I'm looking to integrate an enterprise application behind a firewall with Salesforce, what considerations should I be making? From the architect certification study guide Given a scenario, ...
2
votes
0answers
101 views

Get Chatter Group Link with URLFOR

Would like to add a link to a chatter group to a visualforce page. Following best practices was trying to use {!URLFOR()} so the page doesn't break if the chatter group url format changes. However, I ...
5
votes
2answers
140 views

Is there a more efficient way of getting an object by related list?

I've started programming in Salesforce in January 2015. Most of my code uses this methodology : : List<String> accountIds = new List<String>(); for(Account account : accounts) { ...
1
vote
2answers
63 views

Using field tooltips - What's best practice? [closed]

What's the best practice for when/if to add field help text? Should every field have help text or only the fields where the field label is not self-explanatory? Note: This is a business question, ...