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: DecodableParameters
methodName of the Apex method to call.
namespaceManaged package namespace, if any. Optional.
relativePathPath to the Apex REST service, as defined in the
urlMappingof the@RestResourceannotation on the target class.queryItemsOptional query items to include in the request.
headersOptional
HTTPheaders to include in the request.bodyRequest body for a
POST,PATCHorPUTrequest.validatorValidator to validate the server response.
decoderJSON decoder to use to decode the results.
sessionURL session for the request.
allowsLoginIf 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
sessionURL session for the request.
allowsLoginIf 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
soqlA SOQL query.
batchSizeA 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.
sessionURL session for the request.
allowsLoginIf 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
QueryResultofDecodableinstances. # Reference -
Retrieves the next page of query results.
If the initial query returns only part of the results, the
QueryResultwill contain a value innextRecordsPathwhich can be used as thepathargument for this method.Declaration
Swift
func nextResultPage<T: Decodable>( at path: String, session: URLSession = .shared, allowsLogin: Bool = true ) -> AnyPublisher<QueryResult<T>, Error>Parameters
pathThe path to the next page of query results, as returned by the previous call to
queryornextResultPage.sessionURL session for the request.
allowsLoginIf 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
QueryResultofDecodableinstances. # 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
typeType of record (e.g.
Account,ContactorMyCustomObject__c) which has anOwnerIdfield.fieldsFields to retrieve. If nil, then all fields will be retrieved.
limitThe maximum number of rows to return.
batchSizeThe batch size for a query determines the number of rows that are returned in the query results.
userSpecified user, or nil to use the last authenticated user.
sessionURL session for the request.
allowsLoginIf 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 FieldsQueryResultofDecodableinstances. -
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 : DecodableParameters
typeType of record (e.g. “Account”, “Contact” or “MyCustomObject__c”).
idUnique ID of the record; 15 or 18 characters.
fieldsFields to retrieve. If nil, then all fields will be retrieved.
sessionURL session for the request.
allowsLoginIf 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
Decodablerecord # 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 : EncodableParameters
typeType of record (e.g.
Account,ContactorMyCustomObject__c).fieldsDictionary of fields names and values to insert.
sessionURL session for the request.
allowsLoginIf 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 : EncodableParameters
typeType of record (e.g.
Account,ContactorMyCustomObject__c).idUnique ID of the record; 15 or 18 characters.
fieldsDictionary of fields names and values to update.
sessionURL session for the request.
allowsLoginIf 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
typeType of record (e.g.
Account,ContactorMyCustomObject__c).idUnique ID of the record; 15 or 18 characters.
sessionURL session for the request.
allowsLoginIf 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
typeType of record (e.g.
Account,ContactorMyCustomObject__c).sessionURL session for the request.
allowsLoginIf 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
sessionURL session for the request.
allowsLoginIf 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) throwsParameters
urlURL to JSON configuration file. If nil, a file called
Salesforce.jsonin the main app bundle is used by default. -
Declaration
Swift
init(consumerKey: String, callbackURL: URL, defaultAuthHost: String = "login.salesforce.com")Parameters
consumerKeyThe consumer key from your Connected App definition
callbackURLThe callback URL from your Connected App definition
defaultAuthHostHostname 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
userIdentifier 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
userIdentifier for the specified user or, if nil, the last authenticated user. (UserIdentifier is an alias for the user’s identity URL.)
allowsLoginIf 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: DecodableParameters
serviceService
sessionURL session
userUser identifier
allowsLoginIf authentication is required and allowsLogin is true, the user will be prompted to authenticate via the Salesforce-hosted web login form.
validatorValidator
decoderJSON decoder
Return Value
Publisher of decoded output
ConnectedApp Structure Reference