RPA.Salesforce
module RPA.Salesforce
class RPA.Salesforce.Salesforce
Salesforce is a library for accessing Salesforce using REST API. The library extends simple-salesforce library.
More information available at Salesforce REST API Developer Guide.
Dataloader
The keyword execute_dataloader_import can be used to mimic Salesforce Dataloader import behaviour.
input_object can be given in different formats. Below is an example where input is in RPA.Table format in method a and list format in method b.
Example file orders.json
mapping_object describes how the input data fields are mapped into Salesforce object attributes. In the example, the mapping defines that asiakas attribute in the input object is mapped into Tilaaja__c attribute of Tilaus__c custom Salesforce object.
Object type could be, for example, Tilaus__c.
Salesforce object operations
Following operations can be used to manage Salesforce objects:
- Get Salesforce Object By Id
- Create Salesforce Object
- Update Salesforce Object
- Upsert Salesforce Object
- Delete Salesforce Object
- Get Salesforce Object Metadata
- Describe Salesforce Object
There are two ways to set the Salesforce domain. You can set the domain at time of library import or using the Set Domain keyword.
There are several ways to declare a domain at time of library import:
Or using the domain to your Salesforce My domain:
The domain can also be set using the keyword Set Domain:
Examples
Robot Framework
Python
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
variable account
method add_product_into_opportunity
Add Salesforce Product into Opportunity.
Parameters
- product_name β type of the product in the Pricelist
- quantity β number of products to add
- opportunity_id β identifier of Opportunity, default None
- pricebook_name β name of the pricelist, default None
- custom_total_price β price that overrides quantity and product price, default None
- Returns: True is operation is successful or False
method auth_with_connected_app
Authorize to Salesforce with security token, username, password, connected app key, and connected app secret creating instance.
Parameters
- username β Salesforce API username
- password β Salesforce API password
- api_token β Salesforce API security token
- consumer_key β Salesforce connected app client ID
- consumer_secret β Salesforce connected app client secret
- embed_api_token β Embed API token to password (default: False)
Python
Robot Framework
method auth_with_token
Authorize to Salesforce with security token, username and password creating instance.
Parameters
- username β Salesforce API username
- password β Salesforce API password
- api_token β Salesforce API security token
method create_new_opportunity
Create Salesforce Opportunity object.
Parameters
- close_date β closing date for the Opportunity, format βYYYY-MM-DDβ
- opportunity_name β as string
- stage_name β needs to be one of the defined stages, defaults to βClosed Wonβ
- account_name β by default uses previously set account, defaults to None
- Returns: created opportunity or False
method create_salesforce_object
Create Salesforce object by type and data.
Parameters
- object_type β Salesforce object type
- object_data β Salesforce object data
- Raises: SalesforceDataNotAnDictionary β when object_data is not dictionary
- Returns: resulting object as dictionary
method delete_salesforce_object
Delete Salesfoce object by type and id.
Parameters
- object_type β Salesforce object type
- object_id β Salesforce object id
- Returns: True if successful
method describe_salesforce_object
Get Salesfoce object description by type.
- Parameters: object_type β Salesforce object type
- Returns: object description as dictionary
method execute_apex
Execute APEX operation.
The APEX classes can be added via Salesforce Developer console (from menu: File > New > Apex Class).
Permissions for the APEX classes can be set via Salesforce Setup (Apex Classes -> Security).
Parameters
- apex β endpoint of the APEX operation
- apex_data β data to be sent to the APEX operation
- apex_method β operation method
- kwargs β additional arguments to be passed to the APEX request
- Returns: result of the APEX operation
Python
Robot Framework
method execute_dataloader_insert
Keyword mimics Salesforce Dataloader βinsertβ behaviour by taking in a input_object`representing dictionary of data to input into Salesforce, a `mapping_object representing dictionary mapping the input keys into Salesforce keys, an object_type representing Salesforce object which Datahandler will handle with operation type.
Stores operation successes into Salesforce.dataloader_success array. Stores operation errors into Salesforce.dataloader_errors.
These can be retrieved with keywords get_dataloader_success_table and get_dataloader_error_table which return corresponding data as RPA.Table.
Parameters
- input_object β filepath or list of dictionaries
- mapping_object β filepath or dictionary
- object_type β Salesforce object type
- Returns: True if operation is successful
method get_dataloader_error_table
Return Dataloader error entries as RPA.Table
method get_dataloader_success_table
Return Dataloader success entries as RPA.Table
method get_domain
Used to determine the current domain that has been set
- Returns: string of the currently set domain
method get_opportunity_id
Get ID of an Opportunity linked to set account.
- Parameters: opportunity_name β opportunity to query
- Returns: Id of the opportunity or False
method get_pricebook_entries
Get all pricebook entries.
- Returns: query result
method get_pricebook_id
Get ID of a pricelist.
Returns False if unique Id is not found.
- Parameters: pricebook_name β pricelist to query
- Returns: Id of the pricelist or False
method get_products_in_pricelist
Get all products in a pricelist.
- Parameters: pricebook_name β pricelist to query
- Returns: products in dictionary
method get_salesforce_object_by_id
Get Salesforce object by id and type.
Parameters
- object_type β Salesforce object type
- object_id β Salesforce object id
- Returns: dictionary of object attributes
method get_salesforce_object_metadata
Get Salesfoce object metadata by type.
- Parameters: object_type β Salesforce object type
- Returns: object metadata as dictionary
property instance
method read_dictionary_from_file
Read dictionary from file.
- Parameters: mapping_file β path to the file
- Returns: file content as dictionary
method salesforce_query
Perform SQL query and return result as dict or Table.
Parameters
- sql_string β SQL clause to perform.
- as_table β Set to True if the result should be of RPA.Tables.Table type. (dictionary is returned by default)
- Returns: Result of the SQL query.
method salesforce_query_result_as_table
Shorthand for Salesforce Query ${sql_string} as_table=${True}
.
- Parameters: sql_string β SQL clause to perform.
- Returns: Result of the SQL query as RPA.Tables.Table.
property session_id
method set_account
Set account name and id by giving either parameter.
Can be used together with keywords: : - get_opportunity_id
- create_new_opportunity
Parameters
- account_name β string, defaults to ββ
- account_id β string, defaults to ββ
- Returns: True if account was found from Salesforce, else False
method set_domain
Used to set the domain the Auth With Token keyword will use. To set the domain to βtestβ or if using a sandbox environment use βsandboxβ as the domain. If you have a Salsesforce My domain you may also input that name. If the domain argument is not used the default domain is βloginβ.
- Parameters: domain β βsandboxβ or the name of the Salesforce My domain; if no argument provided defaults to βloginβ
method set_pricebook
Sets Pricebook to be used in Salesforce operations.
- Parameters: pricebook_name β pricelist to use
method update_salesforce_object
Update Salesfoce object by type, id and data.
Parameters
- object_type β Salesforce object type
- object_id β Salesforce object id
- object_data β Salesforce object data
- Raises: SalesforceDataNotAnDictionary β when object_data is not dictionary
- Returns: True if successful
method upsert_salesforce_object
Upsert Salesfoce object by type, id and data.
Parameters
- object_type β Salesforce object type
- object_id β Salesforce object id
- object_data β Salesforce object data
- Raises: SalesforceDataNotAnDictionary β when object_data is not dictionary
- Returns: True if successful