RPA.Salesforce

Add Salesforce Product into Opportunity.

Arguments

ArgumentTypeDefault valueDescription
product_namestrnulltype of the product in the Pricelist
quantityintnullnumber of products to add
opportunity_idstr, NoneNoneidentifier of Opportunity, default None
pricebook_namestr, NoneNonename of the pricelist, default None
custom_total_pricefloat, NoneNoneprice that overrides quantity and product price, default None
param product_name:
 type of the product in the Pricelist
param quantity:number of products to add
param opportunity_id:
 identifier of Opportunity, default None
param pricebook_name:
 name of the pricelist, default None
param custom_total_price:
 price that overrides quantity and product price, default None
return:True is operation is successful or False

Authorize to Salesforce with security token, username, password, connected app key, and connected app secret creating instance.

Arguments

ArgumentTypeDefault valueDescription
usernamestrnullSalesforce API username
passwordstrnullSalesforce API password
api_tokenstrnullSalesforce API security token
consumer_keystrnullSalesforce connected app client ID
consumer_secretstrnullSalesforce connected app client secret
embed_api_tokenboolFalseEmbed API token to password (default: False)
param username:Salesforce API username
param password:Salesforce API password
param api_token:
 Salesforce API security token
param consumer_key:
 Salesforce connected app client ID
param consumer_secret:
 Salesforce connected app client secret
param embed_api_token:
 Embed API token to password (default: False)

Python

from RPA.Salesforce import Salesforce from RPA.Robocorp.Vault import Vault SF = Salesforce(domain="robocorp-testing-stuff.develop.my") VAULT = Vault() secrets = VAULT.get_secret("salesforce") SF.auth_with_connected_app( username=secrets["USERNAME"], password=secrets["PASSWORD"], api_token=secrets["API_TOKEN"], consumer_key=secrets["CONSUMER_KEY"], consumer_secret=secrets["CONSUMER_SECRET"], )

Robot Framework

*** Settings *** Library RPA.Salesforce domain=robocop-testing-stuff.develop.my Library RPA.Robocorp.Vault *** Tasks *** Authenticate to Salesforce using connected app ${secrets}= Get Secret salesforce Auth with connected app ... username=${secrets}[USERNAME] ... password=${secrets}[PASSWORD] ... api_token=${secrets}[API_TOKEN] ... consumer_key=${secrets}[CONSUMER_KEY] ... consumer_secret=${secrets}[CONSUMER_SECRET]

Authorize to Salesforce with security token, username and password creating instance.

Arguments

ArgumentTypeDefault valueDescription
usernamestrnullSalesforce API username
passwordstrnullSalesforce API password
api_tokenstrnullSalesforce API security token
param username:Salesforce API username
param password:Salesforce API password
param api_token:
 Salesforce API security token

Create Salesforce Opportunity object.

Arguments

ArgumentTypeDefault valueDescription
close_datestrnullclosing date for the Opportunity, format 'YYYY-MM-DD'
opportunity_namestrnullas string
stage_namestrClosed Wonneeds to be one of the defined stages, defaults to "Closed Won"
account_namestr, NoneNoneby default uses previously set account, defaults to None
param close_date:
 closing date for the Opportunity, format 'YYYY-MM-DD'
param opportunity_name:
 as string
param stage_name:
 needs to be one of the defined stages, defaults to "Closed Won"
param account_name:
 by default uses previously set account, defaults to None
return:created opportunity or False

Create Salesforce object by type and data.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
object_dataAnynullSalesforce object data
param object_type:
 Salesforce object type
param object_data:
 Salesforce object data
raises SalesforceDataNotAnDictionary:
 when object_data is not dictionary
return:resulting object as dictionary

Delete Salesfoce object by type and id.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
object_idstrnullSalesforce object id
param object_type:
 Salesforce object type
param object_id:
 Salesforce object id
return:True if successful

Get Salesfoce object description by type.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
param object_type:
 Salesforce object type
return:object description as dictionary

Execute APEX operation.

Arguments

ArgumentTypeDefault valueDescription
apexstrnullendpoint of the APEX operation
apex_dataDict, NoneNonedata to be sent to the APEX operation
apex_methodstrPOSToperation method
kwargsnulladditional arguments to be passed to the APEX request

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).

param apex:endpoint of the APEX operation
param apex_data:
 data to be sent to the APEX operation
param apex_method:
 operation method
param kwargs:additional arguments to be passed to the APEX request
return:result of the APEX operation

Python

from RPA.Salesforce import Salesforce SF = Salesforce(domain="robocorp-testing-stuff.develop.my") # authenticate to Salesforce SF.execute_apex(apex="MyClass", apex_data={"data": "value"}) result = SF.execute_apex( apex="getAccount/?id=0017R00002xmXB1QAM", apex_method="GET")

Robot Framework

*** Settings *** Library RPA.Salesforce domain=robocop-testing-stuff.develop.my *** Tasks *** Executing APEX operations # Authenticate to Salesforce &{apex_data}= Create Dictionary data=value ${result}= Execute APEX MyClass apex_data=${apex_data} ${result}= Execute APEX ... apex=getAccount/?id=0017R00002xmXB1QAM ... apex_method=GET

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.

Arguments

ArgumentTypeDefault valueDescription
input_objectAnynullfilepath or list of dictionaries
mapping_objectAnynullfilepath or dictionary
object_typestrnullSalesforce object 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.

param input_object:
 filepath or list of dictionaries
param mapping_object:
 filepath or dictionary
param object_type:
 Salesforce object type
return:True if operation is successful

Return Dataloader error entries as RPA.Table

Return Dataloader success entries as RPA.Table

Used to determine the current domain that has been set

returns:string of the currently set domain

Get ID of an Opportunity linked to set account.

Arguments

ArgumentTypeDefault valueDescription
opportunity_namestrnullopportunity to query
param opportunity_name:
 opportunity to query
return:Id of the opportunity or False

Get all pricebook entries.

return:query result

Get ID of a pricelist.

Arguments

ArgumentTypeDefault valueDescription
pricebook_namestrnullpricelist to query

Returns False if unique Id is not found.

param pricebook_name:
 pricelist to query
return:Id of the pricelist or False

Get all products in a pricelist.

Arguments

ArgumentTypeDefault valueDescription
pricebook_namestrnullpricelist to query
param pricebook_name:
 pricelist to query
return:products in dictionary

Get Salesforce object by id and type.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
object_idstrnullSalesforce object id
param object_type:
 Salesforce object type
param object_id:
 Salesforce object id
return:dictionary of object attributes

Get Salesfoce object metadata by type.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
param object_type:
 Salesforce object type
return:object metadata as dictionary

Read dictionary from file.

Arguments

ArgumentTypeDefault valueDescription
mapping_filestrnullpath to the file
param mapping_file:
 path to the file
return:file content as dictionary

Perform SQL query and return result as dict or Table.

Arguments

ArgumentTypeDefault valueDescription
sql_stringstrnullSQL clause to perform.
as_tableboolFalseSet to True if the result should be of RPA.Tables.Table type. (dictionary is returned by default)
param sql_string:
 SQL clause to perform.
param 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.

Shorthand for Salesforce Query    ${sql_string}    as_table=${True}.

Arguments

ArgumentTypeDefault valueDescription
sql_stringstrnullSQL clause to perform.
param sql_string:
 SQL clause to perform.
returns:Result of the SQL query as RPA.Tables.Table.

Set account name and id by giving either parameter.

Arguments

ArgumentTypeDefault valueDescription
account_namestrstring, defaults to ""
account_idstrstring, defaults to ""
Can be used together with keywords:
  • get_opportunity_id
  • create_new_opportunity
param account_name:
 string, defaults to ""
param account_id:
 string, defaults to ""
return:True if account was found from Salesforce, else False

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".

Arguments

ArgumentTypeDefault valueDescription
domainstrlogin"sandbox" or the name of the Salesforce My domain; if no argument provided defaults to "login"
param domain:"sandbox" or the name of the Salesforce My domain; if no argument provided defaults to "login"

Sets Pricebook to be used in Salesforce operations.

Arguments

ArgumentTypeDefault valueDescription
pricebook_namestrnullpricelist to use
param pricebook_name:
 pricelist to use

Update Salesfoce object by type, id and data.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
object_idstrnullSalesforce object id
object_dataAnynullSalesforce object data
param object_type:
 Salesforce object type
param object_id:
 Salesforce object id
param object_data:
 Salesforce object data
raises SalesforceDataNotAnDictionary:
 when object_data is not dictionary
return:True if successful

Upsert Salesfoce object by type, id and data.

Arguments

ArgumentTypeDefault valueDescription
object_typestrnullSalesforce object type
object_idstrnullSalesforce object id
object_dataAnynullSalesforce object data
param object_type:
 Salesforce object type
param object_id:
 Salesforce object id
param object_data:
 Salesforce object data
raises SalesforceDataNotAnDictionary:
 when object_data is not dictionary
return:True if successful