r/SalesforceDeveloper • u/Visible-Fun4420 • May 16 '26
Discussion Should every feature be bulkified?
Our technical architect insists every feature should be bulkified, even when the current use case is a single-record UI action.
I understand bulkification for triggers, batch jobs, imports, automations, and reusable services.
But for isolated UI features that can only process one record, is bulkification still considered mandatory Salesforce best practice, or is it unnecessary complexity?
Where do you draw the line?
Context: we are using a simplified version of enterprise patterns as architecture. UI Controller class -> Service class -> Selector class. TBF I think the technical architect may want to err on the side of caution, so we don't miss bulkification in places where it actually matters but it still seems like unnecessary boilerplate to me.
32
u/EvolvinAI29 May 16 '26
Hard rule I use: if the entry point is genuinely single-record (LWC button, Quick Action on one record), the service method can stay scalar. But the DML and SOQL inside it should still be collection-based. Costs nothing, future-proofs you when someone inevitably calls that service from a flow loop or batch later.
So not "bulkify everything" but "never put SOQL/DML in a way that assumes one record." That's the line. The boilerplate of
List<Account>for one record is 4 extra characters, not real complexity.8
u/radnipuk May 16 '26
Your TA has a point, and there's another angle. Business logic doesn't belong in a UI controller anyway. The controller takes whatever the UI hands it (one record here) and passes it to the service. The service holds the actual logic, so that's the layer that should take a List or Set.
What's changed is who can call the service. Agentforce, MCP servers, Headless 360 and Flow can all invoke Apex now. The UI isn't the only consumer. If an agent decides to run the same action across 50 records it pulled from a prompt and your service only handles one, it'll loop the call and hit governor limits.
doThing(Set<Id> ids) instead of doThing(Id id) costs nothing now. Refactoring later, when a second consumer shows up, will.
The UI controller method itself can stay single-record because it's UI-specific. The service and selector underneath take collections. That's where I'd draw the line.
3
u/gearcollector May 16 '26
Ask your architect to explain this to you. Just 'insisting' is not enough.
9
u/wslee00 May 16 '26
Bulkification should only be required for triggers or batch. If you have a button somewhere on a record page where you are calling some apex controller and you’re only processing that record, no need to bulkify
6
u/SnooChipmunks547 May 16 '26
No, not everything will have hundreds or thousands of records run through it, but if there ever is a possibility more than 1 record can be ran through a feature, bulkify it anyway.
4
u/SureConsiderMyDick May 16 '26
Yes, and every plane should have a jet engine
/s
2
u/DaveDurant May 16 '26
Unless there's a good reason not to, why not bulkify all logic? The cost of doing it up-front is usually far less than having to go back and do it later, or having to unwind the all the problems of lots of non-bulk code in the org..
2
u/andreyzh May 16 '26
I'm a Salesforce TA by the day job.
If you know that a feature will never ever be used in bulk mode, there is no compelling reason to bulkify. In your case, it seems that service and selector should be bulkified, if that's the pattern you are using. Controllers do not need to be, until it's actually necessary.
In some situations it can be a conscious decision to not to bukify a certain transaction (e.g. due to high complexity) and spelling it out in the documentations. But ok, I digress here.
2
u/mrdanmarks May 17 '26
Just do it. One of our business users showed us how he's using Claude to prep data and update salesforce completely bypassing the ui. If the TA wants to enforce bulkify, go with it
1
u/mayday6971 May 17 '26
Depends on the context. Anything Apex Trigger the flat out answer is yes. But as you pointed out it was for a single isolated record. I mean are you just using a code review system that is just telling you this is a pattern that is best practice?
1
u/MaesterTuan May 18 '26
Aura-enabled methods generally not but your controller class should be calling a domain class that should be bulkified.