ConnectedApp
public struct ConnectedApp
Represents a Salesforce Connected App.
Reference
Connected Apps in Salesforce help
-
Represents a call to an Apex class exposed as a REST service.
You can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture. This is done by defining your Apex class with the @RestResource annotation to expose it as a REST resource. Similarly, add annotations to your methods to expose them through REST. For example, you can add the @HttpGet annotation to your method to expose it as a REST resource that can be called by an HTTP GET request.
Declaration
Swift
func apex<T>( method: String? = nil, namespace: String? = nil, relativePath: String, queryItems: [URLQueryItem]? = nil, headers: [String:String]? = nil, body: Data? = nil, validator: Validator = .default, decoder: JSONDecoder = .salesforce, session: URLSession = .shared, allowsLogin: Bool = true ) -> AnyPublisher<T, Error> where T: Decodable
Parameters
method
Name of the Apex method to call.
namespace
Managed package namespace, if any. Optional.
relativePath
Path to the Apex REST service, as defined in the
urlMapping
of the@RestResource
annotation on the target class.queryItems
Optional query items to include in the request.
headers
Optional
HTTP
headers to include in the request.body
Request body for a
POST
,PATCH
orPUT
request.validator
Validator to validate the server response.
decoder
JSON decoder to use to decode the results.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Pubisher # Reference Introduction to Apex REST
-
Gets information about the current user
Declaration
Swift
func identity(session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<Identity, Error>
Parameters
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher.
-
Undocumented
Declaration
Swift
func limits(session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<[String : Limit], Error>
-
Performs a query
Declaration
Swift
func query<T: Decodable>( soql: String, batchSize: Int = 2000, session: URLSession = .shared, allowsLogin: Bool = true ) -> AnyPublisher<QueryResult<T>, Error>
Parameters
soql
A SOQL query.
batchSize
A numeric value that specifies the number of records returned for a query request. Child objects count toward the number of records for the batch size. For example, in relationship queries, multiple child objects are returned per parent row returned. The default is 2,000; the minimum is 200, and the maximum is 2,000. There is no guarantee that the requested batch size is the actual batch size. Changes are made as necessary to maximize performance.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of
QueryResult
ofDecodable
instances. # Reference -
Retrieves the next page of query results.
If the initial query returns only part of the results, the
QueryResult
will contain a value innextRecordsPath
which can be used as thepath
argument for this method.Declaration
Swift
func nextResultPage<T: Decodable>( at path: String, session: URLSession = .shared, allowsLogin: Bool = true ) -> AnyPublisher<QueryResult<T>, Error>
Parameters
path
The path to the next page of query results, as returned by the previous call to
query
ornextResultPage
.session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of
QueryResult
ofDecodable
instances. # Reference Execute a SOQL Query -
Queries all records of the specified type which are owned by the user.
Declaration
Swift
func myRecords<T: Decodable>( type: String, fields: [String]? = nil, limit: Int? = nil, batchSize: Int = 2000, user: UserIdentifier? = nil, session: URLSession = .shared, allowsLogin: Bool = true ) -> AnyPublisher<QueryResult<T>, Error>
Parameters
type
Type of record (e.g.
Account
,Contact
orMyCustomObject__c
) which has anOwnerId
field.fields
Fields to retrieve. If nil, then all fields will be retrieved.
limit
The maximum number of rows to return.
batchSize
The batch size for a query determines the number of rows that are returned in the query results.
user
Specified user, or nil to use the last authenticated user.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of
# Reference Frequently-Occurring FieldsQueryResult
ofDecodable
instances. -
Retrieves a Salesforce record
Declaration
Swift
func retrieve<T>(type: String, id: String, fields: [String]? = nil, session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<T, Error> where T : Decodable
Parameters
type
Type of record (e.g. “Account”, “Contact” or “MyCustomObject__c”).
id
Unique ID of the record; 15 or 18 characters.
fields
Fields to retrieve. If nil, then all fields will be retrieved.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of a
Decodable
record # Reference Working with Records -
Inserts a Salesforce record
Declaration
Swift
func insert<T>(type: String, fields: [String : T], session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<String, Error> where T : Encodable
Parameters
type
Type of record (e.g.
Account
,Contact
orMyCustomObject__c
).fields
Dictionary of fields names and values to insert.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher that emits the ID of the successfully-inserted record, or an error.
-
Updates a Salesforce record
Declaration
Swift
func update<T>(type: String, id: String, fields: [String : T], session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<Void, Error> where T : Encodable
Parameters
type
Type of record (e.g.
Account
,Contact
orMyCustomObject__c
).id
Unique ID of the record; 15 or 18 characters.
fields
Dictionary of fields names and values to update.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher.
-
Deletes a Salesforce record
Declaration
Swift
func delete(type: String, id: String, session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<Void, Error>
Parameters
type
Type of record (e.g.
Account
,Contact
orMyCustomObject__c
).id
Unique ID of the record; 15 or 18 characters.
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher.
-
Retrieves metadata about a Salesforce object
Declaration
Swift
func describe(type: String, session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<ObjectDescription, Error>
Parameters
type
Type of record (e.g.
Account
,Contact
orMyCustomObject__c
).session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of metadata about the object. # Reference sObject Describe
-
Describes all accessible objects in the user’s Salesforce org
Declaration
Swift
func describeAll(session: URLSession = .shared, allowsLogin: Bool = true) -> AnyPublisher<[ObjectDescription], Error>
Parameters
session
URL session for the request.
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
Publisher of an array of object metadata.
-
Initializes a Connected App representation
Throws
Error if the JSON configuration data cannot be decoded.Declaration
Swift
init(url: URL? = nil) throws
Parameters
url
URL to JSON configuration file. If nil, a file called
Salesforce.json
in the main app bundle is used by default. -
Declaration
Swift
init(consumerKey: String, callbackURL: URL, defaultAuthHost: String = "login.salesforce.com")
Parameters
consumerKey
The consumer key from your Connected App definition
callbackURL
The callback URL from your Connected App definition
defaultAuthHost
Hostname for OAuth authentication. Default is “login.salesforce.com”. For sandbox orgs use “test.salesforce.com” or for a custom domain use, for example “somethingReallycool.my.salesforce.com”
-
Logs in a new user and returns the new credential
Declaration
Swift
func logIn() -> AnyPublisher<Credential, Error>
Return Value
Publisher
-
Revokes a user’s refresh and/or access tokens and clears the credential from the local, secure cache.
Reference
Declaration
Swift
func logOut(user: UserIdentifier? = nil) -> AnyPublisher<Void, Error>
Parameters
user
Identifier for the specified user or, if nil, the last authenticated user. (UserIdentifier is an alias for the user’s identity URL.)
Return Value
A publisher that completes when the underlying OAuth2 token revoke request completes.
-
Gets the Credential for the specified user or, if no user is specified, then for the last authenticated user.
Declaration
Swift
func getCredential(for user: UserIdentifier? = nil, allowsLogin: Bool = true) -> AnyPublisher<Credential, Error>
Parameters
user
Identifier for the specified user or, if nil, the last authenticated user. (UserIdentifier is an alias for the user’s identity URL.)
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
Return Value
A publisher of a Credential # Reference
-
Executes an asynchronous request for data from a Salesforce API endpoint. You will likely not need to call this method directly.
Declaration
Swift
func go<S, Output>( service: S, session: URLSession = URLSession.shared, user: UserIdentifier? = nil, allowsLogin: Bool = true, validator: Validator = .default, decoder: JSONDecoder = .salesforce ) -> AnyPublisher<Output, Error> where S: Service, Output: Decodable
Parameters
service
Service
session
URL session
user
User identifier
allowsLogin
If authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
validator
Validator
decoder
JSON decoder
Return Value
Publisher of decoded output