Skip to main content

A basic Salesforce.com REST/Metadata/Soap API client. Base on simple-salesforce.

Project description

SalesforceXytoolsCore is the core of SalesforceXytools-for-sublime. It is base on simple-salesforce.

Support

  • Sobject Record Management : sobject create, get, get_by_custom_id, update, delete
  • Sobject Queries : query, query_more, search, query_allsearch
  • Sobject Bulk action
  • Run Apex Script
  • Metadata Control : describeMetadata, listAllMetadata, getAllMetadataMap, listmeta, listFolder, retrieve, etc.
  • Package.xml builder.
  • Retrieve Metadata to memory, Retrieve Metadata zip file.
  • ApexClass, Trigger, ApexComponent, ApexPage: create, update, delete, get
  • Get Apex Log
  • Run test class

Usage

Requirement

download it , and import to your project

from SalesforceXytoolsCore import *

sobject create, get, get_by_custom_id, update, delete

username = ""
password = ""
soap_api = Soap(username=username, 
                password=password, 
                security_token='', 
                sandbox=True,
                version='40.0'
                )

sobject_name = "Account"
sobject = soap_api.get_sobject(sobject_name)

"""
create a new Sobject in Salesforce
"""
new_account = sobject.create({'Name':'Exia.Huang'})
sobject_id = new_account["id"]
print(new_account)

"""
get a Sobject in Salesforce
"""
sobject1 = sobject.get(sobject_id)
print(sobject1)

"""
get a Sobject by External ID
"""
sobject2 = sobject.get_by_custom_id('My_Custom_ID__c', '22')

"""
update a Sobject in Salesforce
"""
sobject3 = sobject.update(sobject_id,{'LastName': 'Huangxy'})

"""
delete a Sobject in Salesforce
"""
sobject.delete(sobject_id)

Run Apex Script

apex_string = "System.debug('hello world');"
debug_levels = {
        "DB": "Info", 
        "System": "DEBUG", 
        "Workflow": "INFO", 
        "Callout": "INFO", 
        "Validation": "INFO", 
        "Apex_Code": "DEBUG", 
        "Apex_Profiling": "INFO"
    }
result = soap_api.execute_anonymous(apex_string, debug_levels)
print(result)

Metadata Control : describeMetadata, listAllMetadata, getAllMetadataMap, listmeta, listFolder, retrieve, etc.

meta_api = MetadataApi(username=username, 
                password=password, 
                security_token='', 
                sandbox=True,
                version='40.0'
                )

"""
describeMetadata :
    This call retrieves the metadata that describes your organization. 
    This information includes Apex classes and triggers, custom objects, custom fields on standard objects, tab sets that define an app, and many other metadata types.
"""
result = meta_api.describeMetadata()
print(json.dumps(result, indent=4))



"""listAllMetadata """
for meta in meta_api.listAllMetadata():
    print(meta)
    print(meta['type'] + " : " + meta['fullName'] + " : " + meta['fileName'])

"""getAllMetadataMap"""
all_metadata_map = meta_api.getAllMetadataMap()

"""listmeta"""
query_option_list = [
{
    "metadata_type" : "EmailFolder",
    "folder" : ""
},
{
    "metadata_type" : "ApexClass",
    "folder" : ""
}
]
listmeta_result = meta_api.listMetadata(query_option_list)
print(len(listmeta_result))
for meta in listmeta_result:
    print(meta)


"""packageTypeList"""
print('>>>packageTypeList')
print(meta_api.packageTypeList())


"""listFolder"""
folder = meta_api.listFolder("EmailTemplate")

"""checkRetrieveStatus"""
retrieve_id = '09Sxxxxxxxxxxxx'
result = meta_api.checkRetrieveStatus(retrieve_id)
print(result)

Retrieve Metadata to memory

"""retrieve"""
result = meta_api.startRetrieve()
print(result)
print(result["done"])
print(result["id"])
print(result["state"])

Retrieve Metadata zip file

"""retrieve zip file"""
meta_api.retrieveZip("C:\\Users\\exia\\workspace","test20180615.zip")

Package.xml builder.

"""buildPackageXml"""
packagexml = meta_api.buildPackageXml()
print('>' * 80)
print('>>>buildPackageXml')
print(packagexml)

Tooling API

ApexClass, Trigger, ApexComponent, ApexPage: create, update, delete, get

tooling_api = ToolingApi(username=username, 
                password=password, 
                security_token='', 
                sandbox=True,
                version='40.0'
                )

"""createApexClass"""
name = "HelloWorld"
body = """public class HelloWorld {
        private String hee;
}"""
status_code, result = tooling_api.createApexClass(name, body)
print(status_code)
print(result)


"""getApexClass"""

"""deleteApexClass"""
id="01pxxxxx"
status_code, result = tooling_api.deleteApexClass(id)
print(status_code)
print(result)

"""updateApexClass"""
body = """public class HelloWorld3 {
        private String hee4;
}"""
print(tooling_api.updateApexClass("01p5D000000FXc5", body))


"""createTrigger"""
tooling_api.createTrigger(tableEnumOrId, name, body)

"""createApexComponent"""
tooling_api.createApexComponent(MasterLabel, name, markup)

"""createApexPage"""
tooling_api.createApexPage(MasterLabel, name, markup)


"""run test class"""
id_list = ['xxx', 'xxxx']
tooling_api.runTestSynchronous(id_list)

"""get apex log"""
log_id = ''
tooling_api.getLog(log_id)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SalesforcexytoolsCore-2.1.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

SalesforcexytoolsCore-2.1-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file SalesforcexytoolsCore-2.1.tar.gz.

File metadata

  • Download URL: SalesforcexytoolsCore-2.1.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.2

File hashes

Hashes for SalesforcexytoolsCore-2.1.tar.gz
Algorithm Hash digest
SHA256 0212529019809fe79512439804252043ce6a909802cb46832940313d9a00e012
MD5 490944d2a7523da92998671432fb0225
BLAKE2b-256 0102778c886f6e99a8d25a289466ea052d68634f795f64caaae733ae7d1354da

See more details on using hashes here.

File details

Details for the file SalesforcexytoolsCore-2.1-py3-none-any.whl.

File metadata

  • Download URL: SalesforcexytoolsCore-2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.2

File hashes

Hashes for SalesforcexytoolsCore-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 485c61f1aca8114f09bcac53679fd756851682a963f036d9f4e50d0e740978fe
MD5 399c05bd70a49081edcc263f97b63b18
BLAKE2b-256 12892e2eae77861fc8e13c585a819dd11d438783f3de3e7831a40b3a1696bb6a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page