Package: veevatools
IntroductionThis python package is a set of Salesforce.com, Veeva Network, Veeva Vault, and Veeva Nitro libraries, scripts, and functions used to help expedite the development of Veeva Tools.Installation / RequirementsEnsure you haveat least Python version 3.10installed.
To Check your installation version, type the following commands in the terminal (MacOs) / command prompt (Windows):python --versionTo install python, go tohttps://www.python.org/then navigate to the download page of your Operating System.You will need to have Packager Installer for Python (pip) installed. To install pip, run the following command in the terminal (MacOs) / command prompt (Windows):curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.pyTo install the Veeva Tools library:pip install veevatoolsTo upgrade to the latest version of Veeva Tools library:pip install veevatools --upgradeOverviewThe Veeva Tools package currently contains 3 major components:Salesforce libraryAuthentication:fromsalesforceimportSffrompandasimportpdsf=Sf()sf.authenticate(sfUsername='yourname@salesforce.com',sfPassword='password123',sfOrgId='00D2C0000008jIK',isSandbox=false)Sidenote on Pandas DataFrames:Pandas DataFrame (pd) is used to prepare the data for import (i.e. create, update methods) and additional export methods such as pd.to_excel() in order to save the output into an Excel file.Additionally, Complex data manipuation (joins, merges, groupbys, filters)and data analytics (describe, statistical analysis) can all be performed using Pandas.To learn more about Pandas DataFrames, go to thePandas documentation<br >
Or just Google tutorials on Pandas DataFrames.This YouTube playlist by Corey Schaferprovides an excellent starting point into the world of Pandas!Data methods:The salesforce class (Sf) contains methods that can help you interact with data and metadata components:Queryaccount_recordtypes=sf.query("SELECT Id, Name, SobjectType from RecordType WHERE SobjectType = 'Account'")]account_recordtypesReturn -> pd.DataFrame():IdNameSobjectType0012f4000001ArT3AAKProfessional_vodAccount1012f4000001ArT4AAKInstitution_vodAccount2012f4000001ArT5AAKMCO_vodAccount3012f4000001ArT6AAKOrganization_vodAccount4012f4000001ArWzAAKHospital_vodAccountSidenote:You can use any Pandas (pd) methods on the return value of the query output. For exampleaccount_recordtypes.to_excel("Account RecordTypes.xlsx")Will save the results of the DataFrame into an Excel file.Create## Takes a DataFrame of CRM records and creates records in CRMaccount_records=pd.DataFrame([{'FirstName':'Test','LastName':'Account'},{'FirstName':'Test2','LastName':'Account2'}])result=sf.create('Account',account_records)resultReturn -> pd.DataFrame():successcreatedId0TrueTrue0010r00000tF7L1AAK1TrueTrue0010r00000tF7L2AAKUpdate### Takes a dataframe that contains at least the Id column### and any other column to be updated, for example, FirstNameupdate_account_name=pd.DataFrame([{'FirstName':'Updated','Id':'0010r00000tF7L1AAK'},{'FirstName':'Name','Id':'0010r00000tF7L2AAK'}])result=sf.update('Account',update_account_name)resultReturn -> pd.DataFrame()successcreatedId0TrueFalse0010r00000tF7L1AAK1TrueFalse0010r00000tF7L2AAKUpsert### Takes a dataframe that contains an external ID column### and any other column to be updated, for example, Name### if the external ID matches an existing record,### the account is updated, otherwise, a new record is createdupsert_account=pd.DataFrame([{'NET_External_Id__c':'242977178138969088','Name':'Updated Hospital Name'},{'NET_External_Id__c':'555579769212255555','Name':'Create New Hospital'}])result=sf.upsert(object_api='Account',external_id_field_api='NET_External_Id__c',record_dataframe=upsert_account)resultReturn -> pd.DataFrame()successcreatedid0TrueFalse001f400000PKOrwAAH1TrueTrue0010r00000tF7stAACDelete### Takes a dataframe that contains the Id column### deletes records listed based on their SFID.delete_account=pd.DataFrame([{'Id':'0010r00000tF7stAAC'},{'Id':'001f400000PKOrwAAH'}])result=sf.delete(object_api='Account',record_dataframe=delete_account)resultReturn -> pd.DataFrame()successcreatedId0TrueFalse0010r00000tF7stAAC1TrueFalse001f400000PKOrwAAHRead Metadata###Create Metadata###Update Metadata###Rename Metadata###Delete Metadata###List MetaData###