Closed perbrondum closed 3 years ago
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.
Cool. Thanks. We will try that.
We tried the apex REST call but got stuck on getting access to the sessionId. Is there a trick to get the sessionId from connectedApp inside swift?
Thanks again for supporting swiftlysalesforce.
Per
On Jul 28, 2021, at 6:36 PM, Michael Epstein @.***> wrote:
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.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@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.
Awesome. Thank you.
Per
On Jul 29, 2021, at 9:37 PM, Michael Epstein @.***> wrote:
@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.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
This is very cool, except I can’t seem to get the return type right (which I assume is json with status of the job).
*private* *func* bulkDeleteContent(type: contentSegment) {
DB.salesforce.identity().sink(receiveCompletion: { (completion) *in*
*switch* completion {
*case* .finished:
*break*
*case* *let* .failure(error) :
print("Failed to login. Error: \(error)")
}
}) { identity *in*
// Call relevant APEX
*let* method : HTTPMethod = .delete
*let* path = "/\(instanceName).salesforce.com/services/apexrest/
(type)"
DB.salesforce.apex(method: method,
path: path,
parameters: [:],
body: *nil*,
headers: *nil*,
config:
Salesforce.RequestConfig()).sink(receiveCompletion: { (completion) in
*switch* completion {
*case* *let* .failure(error):
print("Failed to execute Apex. Error:
(error)")
*case* .finished:
print("Success executing Apex \(type)")
*break*
}
}, receiveValue: { result *in*
//
}).store(in: &*self*.subscriptions)
}.store(in: &*self*.subscriptions)
}
Error: Unable to infer type of a closure parameter 'result' in the current context
Per B Jakobsen CEO Tap2Sales.com @.***
On Jul 29, 2021 at 9:52:51 PM, Per Jakobsen @.***> wrote:
Awesome. Thank you.
Per
On Jul 29, 2021, at 9:37 PM, Michael Epstein @.***> wrote:
@perbrondum https://github.com/perbrondum if you use Swiftly Salesforce's apex https://github.com/mike4aday/SwiftlySalesforce/blob/60c9506808b3c4e62f5f1cbfbd9c6e8061458315/Sources/SwiftlySalesforce/ConnectedApp%2BApex.swift#L29 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 https://github.com/mike4aday/SwiftlySalesforce/blob/60c9506808b3c4e62f5f1cbfbd9c6e8061458315/Sources/SwiftlySalesforce/ConnectedApp.swift#L74 .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mike4aday/SwiftlySalesforce/issues/132#issuecomment-889406280, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALCYWDGZR2NZJXMJ6Z7M7LLT2GUVVANCNFSM5A5XE5VA .
Hi @perbrondum It's difficult for me to follow the unformatted code, but let me offer this:
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.)identity
before calling the apex
publisher.@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.
Trying to truncate custom objects via the API i've hit a dead stop. One workaround would be to execute the following Apex: // List contentDelete = New List();
contentDelete = [SELECT CreatedById FROM WIWO_Content__c LIMIT 10000];
delete contentDelete;
//
Is there some way to call Anonymous Apex inside SwiftlySalesforce?