Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [design-patterns]

A general reusable solution to a commonly occurring problem within a given context in software design

12
votes
1answer
612 views

Apex Framework / library for consuming REST services

To consume REST services there is a lot of boilerplate code needed: Build Apex Objects to model the responses Code to deserialize REST responses to those classes Handling of HTTP requests, responses ...
1
vote
1answer
31 views

Design Pattern for Updating Records?

A while back I wrote an Apex class to handle opportunity splits. I couldn’t use the Opportunity Splits object because there were splits on three different corporate levels (with one-to-many or many-...
0
votes
1answer
127 views

call Messaging Queue every 5 Minutes [closed]

I want to make Integration between Salesforce and ActiveMQ(Is is a messaging server where the company send and save messages in this service). The Context: Every 5 Minutes should salesforce a ...
1
vote
2answers
54 views

How to use trigger design pattern: ERROR Constructor not defined: [CaseTriggerHandler].<Constructor>()

I am trying to follow the best practice design patterns for triggers but get the error Constructor not defined: [CaseTriggerHandler].(). What am I missing? Trigger trigger CaseTrigger on Case (...
1
vote
1answer
391 views

fflib apex common Usage [closed]

We have a existing salesforce implementation, we have most of the logic in triggers and trigger handlers. We are still using classic and no mobile or other UI. But still we are planning to implement ...
2
votes
1answer
156 views

Trigger design pattern - Where to add decision making logic?

Looking for some suggestions/lessons learned, etc., regarding where to add the decision-making code that determines if some code should run after a particular field update in a trigger context. For ...
1
vote
2answers
79 views

Design pattern for an attachment trigger using trigger framework?

Hoping to tap into the wisdom of the Apex design pattern wizards out there. We have recently moved to a trigger framework in order to decouple and standardize our wildly disparate trigger code ...
2
votes
2answers
157 views

Are Custom Labels Cached?

There was a requirement to store some key value pairs that will be frequently accessed and the current setup is that is being stored in custom labels. I was wondering if there is any evidence of ...
1
vote
1answer
41 views

How Exactly Do the Class and Trigger Connect in this Design Pattern?

Early on as an Apex developer, I adopted the following one-trigger-per-object design pattern: Class public with sharing class caseTriggerHandler { public static boolean firstRun = true; ...
1
vote
2answers
226 views

How to Lock/Restrict/Block record from change in Salesforce Lightning

BACKGROUND I am updating an external accounting system with information from custom objects like Invoice Credit Note Payment Transaction The Invoice and Credit Note custom objects have Status ...
0
votes
1answer
42 views

Best practice for managing a large number of email templates

I am interested to understand what is best practices when managing an org with 100+ email templates. Specially in the circumstance where there is additional logic which needs to control which email ...
0
votes
0answers
23 views

Share a function among two apex classes

I have two class that both have this function @AuraEnabled public static String talkToAuthorizeDotNet(String body){ return AuthorizeDotNetUtility.makeCallout(body); } Is there a better way to ...
9
votes
2answers
809 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 (...
4
votes
1answer
68 views

What is too many functions?

While reading through on some lightning documentation I came across this piece regarding Anti-Patterns. I have definitely had some helpers which have run the risk of embodying that anti pattern. How ...
0
votes
1answer
464 views

How to mark a Salesforce Contract record as canceled or terminated?

I understand once a contract has been Activated, the status cannot be changed. However, there are times when a contract is terminated (ends early) and there needs to be a way to indicate this. Are ...
1
vote
1answer
110 views

In a custom framework, should Triggers be allowed to retrigger by default?

I am developing a Trigger framework for our org and I’m faced with a decision of whether to automatically disable a Trigger once triggered or to keep enabled. I’ve got enableTrigger() and ...
-1
votes
2answers
306 views

Separation of Concerns? [closed]

I would learn more about SoC in Salesforce but I have a question. Are these concepts really used during the projects or are only "theoretical and academic concepts" never used in real life for ...
2
votes
1answer
27 views

Can Interface declare only methods?

I have created the following interface and a class that implements it. global interface SampleInterface { String logicA(); } public class SampleClass implements SampleInterface { public ...
4
votes
2answers
282 views

Are there ever exceptions to the one trigger per object rule?

I know from this blog post and this answer that a one trigger design pattern per object is ideal. Are there ever exceptions to that rule? If so, what are they? Here is my situation to argue that ...
15
votes
1answer
164 views

Would it be a good/bad idea to develop Lightning Components as “Pure Components”?

As a developer, I enjoy playing with different technologies and seeing what I can learn from, and what ideas I might bring back when working on SFDC (my bread and butter). I'm currently looking at ...
0
votes
0answers
70 views

Utility methods failing with 'cannot call test methods in non-test context'

I generate a number of different email notifications from Cases, with variations depending on Account location, for example. They've morphed from basic workflow email templates in order to gather ...
5
votes
1answer
145 views

What value is there in an Application Service Provider

As I implement Andrew Fawcett's, Apex Common library referring to the fflib-apex-common-samplecode when necessary, I note that his ObjectService classes (i.e. OpportunitiesService.cls) are really more ...
2
votes
0answers
62 views

Using Abstract and Interface Class - Building application in Salesforce

I have been intrigued by using design patterns, Object oriented concepts when programming. I do not have much hands on with using these concepts when programming salesforce. I do have a theoretical ...
-1
votes
1answer
19 views

In single page how to create Account list, records need to show in below columns AccountName, Total number of contacts on Account

public class wrapperClassController1 { public List<aAccount> AccountList {get; set;} public integer ccount {get; set;} public List<aAccount> getAccounts() { if(AccountList == null) { ...
9
votes
1answer
1k views

Lightning Components Design Patterns

We are starting to develop a number of Lightning Components and we are struggling because of lack of well-established design patterns: Where does global constant go and how they can be shared across ...
2
votes
1answer
190 views

MocksApex - behaviour verification

I am using the ApexMocks framework and I am having the following error message: Class.MockTest.testBehavior: line 13, column 1 11:53:56.3 (10709808)|FATAL_ERROR|System.NullPointerException: ...
2
votes
1answer
86 views

Safely refactoring public methods in apex classes

True or False: When refactoring legacy methods (e.g. adding a parameter or deleting altogether), it is guaranteed not to break anything as long as I update every reference in the code base, based on ...
1
vote
1answer
69 views

Help with business logic implementation (triggers VS field updates) and how to apply big refactors

I have some additional business logic I need to put into my QuoteLineItem object, but we have come to a situation where current logic is too spread across triggers and workflow rules + field updates ...
7
votes
1answer
139 views

Reusable Service Class's methods to handle Multi-Level Cloning and related Operation which can be called from Trigger/WebService/Controller

We have a SurveyApp where we deal with following objects: 1) Assessment 2) Section (Lookup to Assessment) 3) Question (Lookup to Section) 4) AnswerOption (Lookup to Question) Inorder to handle ...
1
vote
1answer
369 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) ...
7
votes
3answers
991 views

Lightning component code optimization - capture helper enqueued callback within controller method

So I have the following structure: Lightning Controller ({ doInit : function(....){ helper.getDataFromServer(......); }, onSelectChangeFunction(.....){ component.set("v....
0
votes
1answer
156 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 ...
1
vote
1answer
178 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 ...
2
votes
1answer
150 views

Decorator Pattern: Preventing Setter and Getter properties deadlock

I am only able to set one-sided conversion: either Bitcoin to USD or USD to Bitcoin. But I want both-sided conversion to work which is creating deadlock in Apex. Following is the wrapper class: ...
2
votes
1answer
2k views

REST error handling design

I have created a very simple REST service to convert a lead: @RestResource(urlMapping='/ConvertLeadFromApp/*') global with sharing class RESTLeadConvertController { @HttpGet global static ...
1
vote
2answers
576 views

Trigger, preventing user from deleting campaign unless criteria met

Would love some guidance. Criteria : Only the Campaign Owner can delete a campaign. If any contact member has a campaign member statuses passed 'Sent' then the campaign can not be deleted. I would ...
2
votes
3answers
502 views

Invoking trigger without any changes in the existing records or creating a new record

Is it possible to invoke a trigger without making any changes to the existing records or without creating a new record?
0
votes
1answer
451 views

ApexMocks: setMock() not working

I'm trying to unit test a very simple Account service but for some reason it appears the setMock() is not working. I'm using the following unit test example as a guide and I'm pretty positive I ...
3
votes
1answer
58 views

Building a better Controller - Navigation

Our organization relies heavily on Public Site Visual Force pages for data collection from our user community. These sites contain about a dozen or so VF Pages. The entire site controlled by a ...
6
votes
2answers
1k views

Apex - return this

I came across the following code. Is there any reason why it has used used return this? public class EmailUtil { private Messaging.SingleEmailMessage singleEmailMessage; private final ...
3
votes
2answers
476 views

Patterns of Enterprise Application Architecture (PEAA) for Apex

When I was first introduced to Salesforce our company was medium size, with many straightforward Trigger based business processes. Since then we have merged into a large company with many strategic ...
1
vote
2answers
209 views

Apex Enterprise Patterns: Including @IsTest in base classes

I'm looking to implement some of the ideas presented by Andrew Fawcett and his Apex Enterprise Patterns. Basic idea is to employ the design patterns that he documents very well, but not his fflib ...
5
votes
2answers
875 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 ...
1
vote
0answers
65 views

Optimal Integration Pattern (bi-directional Sync) to use - Case and Incident Sync

We are currently evaluating the optimal integration pattern (both Inbound and Outbound) to be used for our Service Cloud implementation. A simple use case is to synchronize Cases and Incidents (bi-...
0
votes
0answers
71 views

Picklist or Custom Metadata or Custom Object or else?

I have to design something like this : User can rate 1 to 10 on Competent ,Frequency , Strength . But each level define different based on category for example : 1 for Competent is 'do this and that ...
2
votes
2answers
716 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, ...
4
votes
3answers
128 views

Please advice is this a good design for my VFP rendered in PDF

i have a VFP that rendered in PDF format for my Quote. And due to the limitation whereby long text doesnt word-wrap in my table , i decided to loop through my long text content and put a line break ...
5
votes
1answer
411 views

How to make sure managed package triggers execute successfully even if custom triggers fail on a packaged object?

I have developed triggers on a managed package object which gets updated through a webhook service. The webhook updates some external id and status fields which are critical to get updated regardless ...
7
votes
4answers
12k views

Trigger Handler, what's its purpose?

I have a requirement to comment all the code of an apex class called AccountTriggerHandler that I did not code. I have no way of contacting the programmer that made the class. I'm trying to figure out ...
2
votes
1answer
140 views

Central class for calling static methods in Data Access Layer

Much like the Factory pattern I am looking for a good way to call the desired Data Access methods through a central class. Unfortunately, my DAL classes are static (as I need them to cache records) so ...