Skip to main content

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 Id
  • info gives an overview of the functions and methods within the pandaforce package
  • isNull: Returns boolean value for passed value indicating if it is a Null or NaN value
  • repairCasing: 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 data
  • getdf: Returns pandas dataframe from passed SOQL query
  • getObjectFields: Returns list of all field names in the passed Salesforce object name
  • getObjectFieldsDict: Returns all fields of passed Salesforce object name as {label:name} dictionary
  • getReport: 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 username
  • password = string of your Salesforce login password
  • orgid = 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.

  • securitytoken defaults to a blank string (''), but can accept your login security token
  • sandbox defaults to False, but must be passed as True to 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 string
  • uptype: the type of CRUD function to be executed. Options are insert, update, delete, and hard_delete as a string
  • data: this parameter must be a list of dictionaries. 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}
    • delete and hard_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.

Release files for pandaforce 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandaforce 1.1.0
File Size Uploaded
pandaforce-1.1.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pandaforce 1.1.0
File Interpreter ABI Platform
pandaforce-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / pandaforce-1.1.0.tar.gz

Download URL pandaforce-1.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1e815a4c96990e64bbc326a5b0dab72d682a04b5649aea36a205d520967d20c2
BLAKE2b-256 checksum
How to use checksums
e3d49284c56a376fc114bdeb53eb22a65a784440b1e5d706e51f126140a51d74
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pandaforce-1.1.0-py3-none-any.whl

Download URL pandaforce-1.1.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
699acd639e6a521b898b2db49bd8d63b97a03e2275e910c9da9ff3c0a7ed2737
BLAKE2b-256 checksum
How to use checksums
2eee29a63885722041e359b576f4736bd4f2a6920994369082111a687af239f8
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page