Apex Use of Salesforce Function
Why is this an issue?
The Function.get() and Function.invoke() methods were used to retrieve and call Salesforce Functions, a feature that has been retired. Salesforce Functions allowed you to run custom code in elastic compute environments, but this service was discontinued.
Code that calls Function.get() or Function.invoke() will fail at runtime since the underlying service no longer exists. You need to migrate this functionality to an alternative approach.
This rule also flags Salesforce Functions metadata files (.functions-meta.xml). The presence of these files indicates that your project still references Salesforce Functions infrastructure that should be removed.
Examples
Example of incorrect code (synchronous invocation):
public class OrderProcessor {
public void processOrder(Order__c order) {
Map<String, Object> payload = new Map<String, Object>();
payload.put('orderId', order.Id);
// Salesforce Functions has been retired
functions.Function orderFunction = functions.Function.get('MyProject.ProcessOrder');
functions.FunctionInvocation invocation = orderFunction.invoke(JSON.serialize(payload));
}
}
Example of incorrect code (asynchronous invocation):
public class OrderProcessor {
public void processOrder(Order__c order) {
Map<String, Object> payload = new Map<String, Object>();
payload.put('orderId', order.Id);
// Salesforce Functions has been retired
functions.Function orderFunction = functions.Function.get('MyProject.ProcessOrder');
functions.FunctionInvocation invocation = orderFunction.invoke(JSON.serialize(payload), new OrderCallback());
}
}
Example of correct code:
public class OrderProcessor {
public void processOrder(Order__c order) {
// Use Queueable Apex for async processing
System.enqueueJob(new OrderProcessorQueueable(order.Id));
}
}
Example of incorrect metadata (Salesforce Functions definition):
<!-- ProcessOrder.functions-meta.xml -->
<FunctionReference xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Process orders asynchronously</description>
<label>ProcessOrder</label>
</FunctionReference>
Remove the .functions-meta.xml files and the associated functions directory from your project once you have migrated to an alternative solution.
How can I fix violations?
Migrate away from Salesforce Functions to one of these alternatives:
Queueable Apex: For async processing within Salesforce
Platform Events: For event-driven architecture
External Services: For calling external APIs
Heroku or AWS Lambda: For custom compute needs outside Salesforce
Resources
