Questions tagged [design-patterns]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
25 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
1answer
65 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
1answer
39 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
1answer
29 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
1answer
32 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, ...
3
votes
0answers
47 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
0answers
35 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
0answers
133 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
1answer
189 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
1answer
39 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
1answer
17 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. ...
8
votes
1answer
137 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
1answer
102 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
1answer
43 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
2answers
55 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
1answer
46 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
3answers
612 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 ...
22
votes
2answers
1k 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
34 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
439 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
149 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
2k 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
1answer
503 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
151 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
468 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
76 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
607 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
58 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
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 ...
10
votes
2answers
1k 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
99 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
1k 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
160 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
611 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
41 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 ...
5
votes
2answers
427 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
171 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
198 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
207 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
68 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
25 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
227 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
119 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
91 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
184 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 ...
2
votes
1answer
658 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
1k 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
259 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
185 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 ...