Using with Custom Endpoints
There are instances where the standard rest API may not meet all your needs. This typically happens if:
You need more transactional control over a series of operations
The end user does not have access to object/fields/operations you need to perform
This is a public endpoint and you need to enforce logic on the server-side
We can still call these custom endpoints using ts-force
and often even use our generated classes with the request and response.
@RestResource
@RestResource(urlMapping='/myservice')
global with sharing class RestServiceTesting {
@HttpPost
global static Account doPost(Account acc) {
return acc;
}
}
Invokable
A special method invokeAction
is provided to make it easier to call invokable methods
public class AccountInsertAction {
@InvocableMethod(label='Insert Accounts' description='Inserts the accounts specified and returns the IDs of the new accounts.')
public static List<ID> insertAccounts(List<Account> accounts) {
Database.SaveResult[] results = Database.insert(accounts);
List<ID> accountIds = new List<ID>();
for (Database.SaveResult result : results) {
if (result.isSuccess()) {
accountIds.add(result.getId());
}
}
return accountIds;
}
}
@RemoteAction
If you are running inside a VisualForce page, you may want to use @RemoteActions to call dedicated controller code.
public class MyController{
@RemoteAction
public static String foo(Account acc) {
return "hello world";
}
}
See remote-action-promise for more details on calling @RemoteActions
from VisualForce apps.
Last updated
Was this helpful?