A pandas and simple-salesforce based utility package
Project description
PandaForce
A utility package utilizing pandas and simple-salesforce
Overview
pandaforce contains the following general utility functions:
convertTo18: Converts the passed Salesforce 15-digit ID to an 18-digit Idinfogives an overview of the functions and methods within the pandaforce packageisNull: Returns boolean value for passed value indicating if it is a Null or NaN valuerepairCasing: Changes 18-digit IDs that have had all character's capitalized to a Salesforce viable 18-digit Id
It also contains a login class which initiates a connection to a Salesforce org. It contains the following methods:
dml: Runs the specified bulk CRUD command with the passed datagetdf: Returns pandas dataframe from passed SOQL querygetObjectFields: Returns list of all field names in the passed Salesforce object namegetObjectFieldsDict: Returns all fields of passed Salesforce object name as {label:name} dictionarygetReport: Returns pandas dataframe from passed Salesforce report Id (15 or 18 digit)isObject: Accepts string argument. Returns boolean.
Connecting to a Salesforce Org
To connect to your Salesforce Org, create a login class instance with var = pandaforce.login(). login requires the following parameters:
username= string of your Salesforce login usernamepassword= string of your Salesforce login passwordorgid= string of your Salesforce organization id, as found on the Company Information setup page of your org
There are also two optional parameters, securitytoken and sandbox.
securitytokendefaults to a blank string (''), but can accept your login security tokensandboxdefaults toFalse, but must be passed asTrueto access a sandbox within of your org. If you are accessing a sandbox, you must also append'.your_sandbox_name'to the end of your username, as you would when logging in to a normal Salesforce sandbox.
You can have any number of login instances running within a given script. Each instance should be assigned to a different variable. The default example login instance in this document will be sf.
Login Class Methods (Details)
checkObject
The isObject method accepts one string parameter, and searches your Salesforce org for an object with a name matching that parameter. It is not case sensitive. The search is by object name, not object label, so make sure to inlude underscores (_) and to append __c for custom objects.
The method returns boolean. True means the object was found in the org's metadata, False means the opposite.
dml
The dml method evokes a bulk CRUD (Created, Update, Delete) command into your Salesforce org. These changes are permanent, so be cautious when using this method.
dml parameters are as follows:
obj: the name of the Salesforce object (not its label) as a stringuptype: the type of CRUD function to be executed. Options areinsert,update,delete, andhard_deleteas a stringdata: this parameter must be alistofdictionaries. Each value in the list represents a record, and the dictionaries must be formatted as noted below:insert: `{'field_names':field_values_as_type_in_salesforce}'update:{'Id':'15_or_18_digit_Id_as_String','field_names':field_values_as_type_in_salesforce}deleteandhard_delete: `{'Id':'15_or_18_digit_Id_as_String'}
dml returns a list of dictionaries, as formatted in the example below:
[{'success': True, 'created': False, 'id': '0030v000000000000B', 'errors': []},
{'success': True, 'created': False, 'id': '0030v000000000000N', 'errors': []},
{'success': False,'created': False,'id': None,'errors': [{'message': 'Please update phone number format to: (XXX) XXX-XXXX',
'fields': ['MobilePhone'],
'statusCode': 'FIELD_CUSTOM_VALIDATION_EXCEPTION',
'extendedErrorDetails': None}]},
To capture the dml results, assign a variable to the dml command. For example:
r = sf.dml('Custom_Object__c','delete','myData')
Insert Example
sf = login(login_criteria_here)
myData = [{'Name':'First Record','Field_A__c':'A value','Number_Field__c':123},
'Name':'Second Record','Field_A__c':'Another value','Number_Field__c':456}]
sf.dml('Custom_Object__c','insert',myData)
Update Example
sf = login(login_criteria_here)
myData = [{'Id':'000000000000001','Name':'First Record','Field_A__c':'A value','Number_Field__c':123},
'Id':'000000000000002','Name':'Second Record','Field_A__c':'Another value','Number_Field__c':456}]
sf.dml('Custom_Object__c','update',myData)
Delete Example
sf = login(login_criteria_here)
myData = [{'Id':'000000000000001'},
'Id':'000000000000002'}]
sf.dml('Custom_Object__c','delete',myData)
Dot Notation Example
Because the login class initiates a Salesforce class from the simple-salesforce package, you can also run a dml statement through dot notation. A dml statement in this fashion would look like the following:
sf.Org.Custom_Object__c.update(myData)
The .Org component between sf. and .Custom_Object__c is required as the Simple Salesforce Salesforce class is housed within the login class instance.
getObjectFields
The getObjectFields method returns list of all field names in the passed Salesforce object name. The passed value must be a string, and be the name of the Salesforce object, not the label (i.e., 'Custom_Object__c' rather than 'Custom Object')
getObjectFieldsDict
The getObjectFieldsDict method returns all fields of passed Salesforce object name as dictionary, using a {label:name} format. Like getObjectFields, the passed string must be the name of the Salesforce object, not the label (i.e., 'Custom_Object__c' rather than 'Custom Object')
getReport
The getReport method returns a pandas dataframe from passed Salesforce report Id (15- or 18-digit). This method only works on tabular Salesforce reports, and will only return the text value of any hyperlinked text (i.e. The 'Name' field on the report will appear in the dataframe as the text of the name, not a link to the record or the record's 15- or 18-digit Id
Pandaforce Inheritance
As its name implies, Pandaforce heavily utilizes pandas and simple-salesforce, so any functionality of those packages will apply to this package as well.
For example, dataframes returned from methods such as getdf() or getReport are pandas DataFrames, so all DataFrame methods from the pandas package will function on it. Likewise, the Org variable in each login instance is a simple-salesforce Salesforce class, and its methods are accessible as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pandaforce-1.1.0.tar.gz.
File metadata
- Download URL: pandaforce-1.1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e815a4c96990e64bbc326a5b0dab72d682a04b5649aea36a205d520967d20c2
|
|
| MD5 |
ca68c090040e6e8114b2d57ba728f4a8
|
|
| BLAKE2b-256 |
e3d49284c56a376fc114bdeb53eb22a65a784440b1e5d706e51f126140a51d74
|
File details
Details for the file pandaforce-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pandaforce-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
699acd639e6a521b898b2db49bd8d63b97a03e2275e910c9da9ff3c0a7ed2737
|
|
| MD5 |
557d2d7e902558cd7821e5050fb035e3
|
|
| BLAKE2b-256 |
2eee29a63885722041e359b576f4736bd4f2a6920994369082111a687af239f8
|