What if almost nobody needs to open Salesforce? Make your custom actions run in user mode
What if the future of Salesforce is one where almost nobody needs to log into Salesforce? I asked that in a LinkedIn post this week, after Microsoft and Salesforce announced Copilotforce. Picture someone starting the da
What if the future of Salesforce is one where almost nobody needs to log into Salesforce?
I asked that in a LinkedIn post this week, after Microsoft and Salesforce announced Copilotforce. Picture someone starting the day in Microsoft Teams, asking Copilot which customers need attention, checking a few orders and updating an opportunity. All without opening Salesforce. Salesforce is still behind everything: the data, the business rules, the permissions, the automations.
At Vantegrate, the AI agents company I co-founded with Francisco Morales, and at EGA Futura, where we build an ERP that runs 100% natively on Salesforce, this changes how we think about one specific thing: custom actions.
What the announcement says about permissions
According to Salesforce's announcement and Microsoft's press release, Salesforce in Microsoft Copilot (public preview) works through authenticated user access, including authenticated Salesforce MCP access, and keeps existing permissions, sharing rules and audit trails. Supported writeback actions require explicit user confirmation and respect existing validation rules.
That covers the standard path. The part you own is everything custom you expose to an assistant or an agent: invocable Apex, Flows that call Apex, REST endpoints. And Apex, by default, runs in system mode.
The problem with system mode
If a user can't see the Margin__c field but you expose an invocable method that queries it in system mode, the assistant can read it on their behalf. Same with sharing: a class declared without with sharing ignores the user's record access.
In a world where people mostly used the Salesforce UI, page layouts and Lightning pages hid a lot of this. When the UI is Copilot, Claude or Slack, the only thing standing between the user and the data is what the org enforces on the server.
User mode for queries and DML
Apex has had user mode database operations for a while. For an action like "approve a payment", the shape I'd use is:
public with sharing class ApprovePaymentAction {
public class Request {
@InvocableVariable(required=true)
public Id paymentId;
}
@InvocableMethod(label='Approve payment'
description='Approves a payment as the running user')
public static List<String> approve(List<Request> requests) {
Set<Id> ids = new Set<Id>();
for (Request r : requests) {
ids.add(r.paymentId);
}
// Enforces object, field and record access of the running user
List<Payment__c> payments = [
SELECT Id, Status__c
FROM Payment__c
WHERE Id IN :ids
WITH USER_MODE
];
for (Payment__c p : payments) {
p.Status__c = 'Approved';
}
List<String> results = new List<String>();
Database.SaveResult[] saves =
Database.update(payments, false, AccessLevel.USER_MODE);
for (Database.SaveResult s : saves) {
results.add(s.isSuccess()
? 'Approved'
: s.getErrors()[0].getMessage());
}
return results;
}
}
Payment__c is just an example object. Three things matter here:
-
with sharingon the class, so record access follows the user. -
WITH USER_MODEon the query, so field and object permissions are enforced instead of silently returning data the user can't see. -
AccessLevel.USER_MODEon the DML, andallOrNone = false, so validation rule messages come back as text the assistant can show the user.
Write error messages for a chat window
Validation rules still run, which is good. But the message will probably be read in a chat, not next to a field. "Invalid value" helps nobody. "To approve this payment, the invoice has to be posted first" does.
Test as a real user, not as admin
The test that catches most problems:
@IsTest
static void salesRepCannotApproveWithoutPermission() {
User rep = [SELECT Id FROM User
WHERE Profile.Name = 'Standard User' AND IsActive = true
LIMIT 1];
Payment__c p = new Payment__c(Status__c = 'Pending');
insert p;
ApprovePaymentAction.Request r = new ApprovePaymentAction.Request();
r.paymentId = p.Id;
System.runAs(rep) {
Boolean blocked = false;
try {
List<String> res = ApprovePaymentAction.approve(
new List<ApprovePaymentAction.Request>{ r });
blocked = res.isEmpty() || res[0] != 'Approved';
} catch (QueryException e) {
// WITH USER_MODE throws when the user lacks object or field access
blocked = true;
}
System.assert(blocked, 'A standard user should not approve payments');
}
}
Adjust the profile and the expected result to your org. The point is to run every action exposed to an assistant under System.runAs with the least privileged user who might call it.
A short checklist before exposing an action
- Class is
with sharing(orinherited sharingwith a clear reason). - Every SOQL in the path uses
WITH USER_MODE. - Every DML uses
AccessLevel.USER_MODE. - Validation messages make sense without a screen.
- Field History Tracking is on for the fields the action changes.
- There's a
runAstest with a low-privilege user.
For an ERP that lives inside Salesforce, like the one we build at EGA Futura, this matters even more, because the actions aren't only about opportunities. They're about payments, invoices and stock. If you want to see what that looks like, here's our native ERP for Salesforce.
The broader take, in Spanish, on what Copilotforce changes for architects is in the full article on EGA Futura Discover.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.