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;
}
}let acc = new Account({
id: '123',
contacts: [new Contact({
firstName: 'john',
lastName: 'doe'
})],
owner: new User({
'email': 'example@gmail.com'
})
});
const sfSob = acc.toJson(
{ dmlMode: 'all', sendChildObj: true, sendParentObj: true }
);
let data = (await new Rest().request.post<SObject>(
'/services/apexrest/myservice',
{ acc: sfSob }
)).data;
const retAcc = Account.fromSFObject(data);
console.log(retAcc.id, retAcc.contacts.length);Invokable
A special method invokeAction is provided to make it easier to call invokable methods
@RemoteAction
If you are running inside a VisualForce page, you may want to use @RemoteActions to call dedicated controller code.
See remote-action-promise for more details on calling @RemoteActions from VisualForce apps.
Last updated
Was this helpful?