Questions tagged [design-patterns]
A general reusable solution to a commonly occurring problem within a given context in software design
125
questions
0
votes
0
answers
39
views
Is there a design pattern for structuring Record Triggered Flows?
Whilst reviewing The Ultimate Guide to Flow Best Practices and Standards from Salesforce, I saw no mention of any design patterns or best practices on how to handle structuring Record Triggered Flows ...
14
votes
2
answers
435
views
Modularize (existing) LWC for reuse and flexible distribution
I am currently breaking a monolithic 1GP Managed package into more modular 2GP packages.
While doing this I also want to decompose chunky LWC components in a way so they can be reused more flexibly ...
0
votes
1
answer
79
views
Why have service classes? (Service Layer Model)
tl;dr - What are the advantages of having handler and service methods separate housed in separate classes, rather than joined in a single class.
Background
Salesforce and others reference using ...
4
votes
2
answers
195
views
How to remove records to be processed from before update trigger
I am working through my first implementation of a trigger + handler framework. I'm trying to figure out what I think is a pretty basic scenario: how to remove items from my trigger so that only those ...
0
votes
1
answer
42
views
Handling Exceptions From Different Parts of the Code
I've got a case where different parts of the code need to handle exceptions differently, and was wondering if there is a pattern or a recommendation for approaching the problem. Let me explain exactly ...
1
vote
0
answers
21
views
Approach to Map Inbound Web Service Request Fields to a Defined Wrapper Class?
We have multiple external systems POSTing callouts to a salesforce custom web service. We need an approach to map the request fields from these external systems to a generic defined wrapper class.
We ...
0
votes
0
answers
39
views
Mapping conversion using Object Schema query or Custom Metadata type?
Background
External system accepts the API callout payload in ID only but in
Salesforce we need Description value to show.
Middle layer convert get APIs data in Description value that used in
...
1
vote
2
answers
96
views
How put inner class into Apex enterprise Pattern Service layer?
I need use structure (or wrapper class) in Apex Enterprise Pattern.
public with sharing class Structure {
public String name { get; set;}
public Integer limit {get; set;}
private ...
0
votes
1
answer
77
views
Apex Enterprise Pattern for universal usability
Everyone!
I have a question - what if i don't want what kind of objects i will get?
One day it is Accounts, next day - Opportunities, etc.
Can I write Application.cls something like this?
{
// ...
6
votes
1
answer
282
views
Heap Size Optimization with commonly reused lists & variables
I recently joined a new, very large, very old org that is in need of optimization. Previously they had a tendency to create brand new, separate utility classes for each new method being called from ...
5
votes
2
answers
343
views
Generic Platform Event - Centralize routing or not?
My App has a single multipurpose Platform Event called MyEvent__e which is emitted by MANY publishers and for MANY Topics.
Receivers and subscribers need to subscribe to the event type and then do ...
0
votes
1
answer
125
views
Pattern to integrate million record if BULK option not available
This is in reference to Integration with a System having millions of records.
However, due to certain limitation we do not want BULK API needs to be implemented . Although there are other options like ...
0
votes
0
answers
33
views
Techniques for managing integration that uses data from two objects which can be updated independently or together
We have an integration that pushes name, title, manager, and a few other fields from our HR system (a managed package on force.com) to a custom c# endpoint that updates active directory.
Name and ...
0
votes
0
answers
131
views
Enterprise Pattern : AccountsSelector: @Override specified for non-overriding method: List<Schema.SObjectField> sptSObjectFieldList()
We have AccountsSelector class extending ApplicationSObjectSelector abstract class from at4dx library.
ApplicationSObjectSelector class has public virtual method getSObjectFieldList()
I have ...
4
votes
2
answers
252
views
If I Use a Loan Pattern is Salesforce smart enough to do a SOQL for loop?
As we know, Salesforce does some magic when you do something like:
for (List<Account> accountList: [SELECT Id, Name FROM Account WHERE Name LIKE 'Acme%']) {
// do stuff
}
... such that the ...
3
votes
1
answer
467
views
Using System.runAs in all tests - Best practice or Antipattern?
When doing functional tests I see many people also check the permissions by using System.runAs(userWithRightPermission) in most of their tests.
I see good reasons for doing this, because then you ...
1
vote
1
answer
219
views
Soft-Delete in Salesforce for All data[For Auditing]
We have a requirement to maintain every data(even deleted also) for approx 10-15 yrs with its Audit history. We have Salesforce-shield is enabled so maintaining Audit data is taken care of by it. ...
0
votes
1
answer
426
views
How Is Apex Singleton Different From Static Trigger Handler?
I've seen people opting for singleton pattern (https://developer.salesforce.com/wiki/apex_design_patterns_singleton) while writing trigger handler classes and some simply defining methods in trigger ...
0
votes
1
answer
205
views
Repository design pattern
Are there any examples for the Repository design pattern?
I've looked at FFlib Selector and The Joys Of Apex but neither attempt to manage the state of queried records.
0
votes
1
answer
480
views
Regular expression is not working as expected in apex
I'm working on design patterns while I'm testing in the anonymous window it's working as expected. But when i trying to implement the same logic it's unable to find matches
My expression:'^([0-9])\\1*$...
0
votes
1
answer
70
views
Design Pattern Help: Extended Interfaces with methods that shared the same functionality/code
I'm trying to figure out the best pattern for the code below (example: not actual code). IOpportunitiesA and IOpportunitiesB are extending the base interface and they have a similar method, ...
4
votes
0
answers
174
views
A folder structure that follow enterprise design patterns
I come from ASP.net background and I used to have a standardized folder structure such as this.
I just jumped on a huge project with a lot of custom code. I'm sick of having to scroll through ...
1
vote
0
answers
73
views
Salesforce API design patterns [closed]
we are moving away from point to point integrations to Mule(API Led integration ) and are in the process of revamping our endpoints and thus having all the endpoints pass through mule anypoint , this ...
1
vote
0
answers
501
views
Dynamic class invocation in trigger - Callable Interface
Recently I was tasked with a project to dynamically call a class from a packaged trigger. This will also clients to hook into their custom logic instead of what is supplied as part of the package.
I ...
6
votes
1
answer
561
views
Can single Trigger by object cause performance issues?
Context
There are a lot of questions and SF developer blogs related to best practices for trigger.
Since several years, I've been following the single trigger object pattern which has a lot of ...
2
votes
1
answer
145
views
Can't create relationship with Account and Custom object when using FF Unit Of work
I working on a class that needs to insert several records and create relationships between them, mostly to the Account object.
I'm passing a deserialized JSON (WrapperRestZopaProviderRequest) to the ...
0
votes
1
answer
46
views
How to prevent aucomponent table from growing in size so that it changes the size of the component?
Hidden Component 3 is a table (not lightning data table.)
It is fetched with some data-- but when the text gets too large (even with truncation), the entire component will grow with the table.
...
9
votes
1
answer
415
views
How to opt out of FLS validation when a SOQL query is run by a trigger?
I have a large Salesforce application with hundreds of SOQL queries. Currently, the code uses Schema.DescribeFieldResult data to determine if the logged in user has rights to each field in the SELECT ...
3
votes
1
answer
186
views
Dynamic Component creation in Lightning webcomponent
As for my analysis Not able to render dynamic Lightning Web Component Dynamic creation of the Lightning Web Components is not yet supported.
Can someone suggest a better approach to render the input ...
3
votes
1
answer
49
views
Using Salesforce as Single Source of Truth [closed]
From a software architecture perspective, are there major issues with using Salesforce as an application's single source of truth (as opposed to a traditional relational database like Postgres)?
It ...
1
vote
2
answers
66
views
Best Practice: dependency on data model names [closed]
BACKGROUND
I need to display some data from another system on a lightning component. Let's say I get a JSON string from the external system as following:
{
"initialStatus": "Active",
"name": "...
-1
votes
1
answer
78
views
Apex-optimized algorithm for "road atlas city distance matrix" style utility data? [closed]
I'd like to automate a business process that currently involves a road-atlas-style "distance chart" as seen here.
When an employee is hand-reviewing records for deduplication, if a given "status" ...
4
votes
3
answers
1k
views
Platform Event Design when Subscribers are Apex Triggers
This is a general design question on how to structure trigger files for platform events. Say I publish a platform event "lead created"
and I want to do several distinct things within the same ...
24
votes
2
answers
3k
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
1
answer
73
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
1
answer
854
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
2
answers
324
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
1
answer
3k
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 ...
3
votes
1
answer
868
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
2
answers
229
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
2
answers
968
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
1
answer
125
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
2
answers
1k
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
1
answer
174
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
0
answers
24
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 ...
11
votes
2
answers
2k
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
1
answer
185
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
1
answer
3k
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
1
answer
218
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 ...
-2
votes
2
answers
1k
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 ...