Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Anonymous Apex? #132

Closed
perbrondum opened this issue Jul 24, 2021 · 7 comments
Closed

Support for Anonymous Apex? #132

perbrondum opened this issue Jul 24, 2021 · 7 comments
Assignees
Labels

Comments

@perbrondum
Copy link

Trying to truncate custom objects via the API i've hit a dead stop. One workaround would be to execute the following Apex:
//
List<WIWO_Content__c> contentDelete = New List<WIWO_Content__c>();
contentDelete = [SELECT CreatedById FROM WIWO_Content__c LIMIT 10000];
delete contentDelete;
//
Is there some way to call Anonymous Apex inside SwiftlySalesforce?

@mike4aday
Copy link
Owner

mike4aday commented Jul 28, 2021

Hi @perbrondum - yes, you could execute anonymous Apex by creating your own struct that conforms to Swiftly Salesforce's Service protocol (example here) and calls the Salesforce Tooling API as described here.

You could also create a custom Apex web service that both queries and deletes records, and then call that web service via Swiftly Salesforce's apex method.

Another alternative: create a custom Service that calls the Salesforce Composite API to delete multiple record IDs as shown here.

@mike4aday mike4aday self-assigned this Jul 28, 2021
@perbrondum
Copy link
Author

perbrondum commented Jul 28, 2021 via email

@mike4aday
Copy link
Owner

@perbrondum if you use Swiftly Salesforce's apex method then you won't need the session ID. You just need to provide the method arguments (or accept the defaults if applicable).

If you do need to retrieve the access token, you could get it via ConnectedApp's getCredential method.

@perbrondum
Copy link
Author

perbrondum commented Jul 29, 2021 via email

@perbrondum
Copy link
Author

perbrondum commented Jul 29, 2021 via email

@mike4aday
Copy link
Owner

Hi @perbrondum It's difficult for me to follow the unformatted code, but let me offer this:

  • For the path argument that you pass to the apex method: you don't need the instance name, but only the string value you defined in the corresponding Apex class' urlMapping attribute of the @RestResource annotation. (Swiftly Salesforce knows the instance name upon user authentication and services/apexrest/ is already assumed.)
  • There's no need to call identity before calling the apex publisher.
  • The return type is JSON with whatever you defined as the return value in the corresponding, server-side Apex method. Define a custom, Swift struct that mirrors the Apex output and then Swiftly Salesforce will automatically deserialize the JSON into that struct.

@mike4aday
Copy link
Owner

@perbrondum here's an example of calling an Apex method exposed as a REST endpoint. The @RestResource annotation is RandomAccount which returns a Salesforce Account record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants