sfq supports retrieving metadata from Salesforce using the Metadata API (MDAPI). This is useful for extracting components like custom objects, Apex classes, and more.
The mdapi_retrieve method retrieves metadata components as a ZIP file containing the component definitions.
Retrieve all components of specific types:
from sfq import SFAuth
sf = SFAuth(
instance_url="https://your-org.my.salesforce.com",
client_id="PlatformCLI",
client_secret="",
refresh_token="your-refresh-token"
)
# Retrieve all CustomObjects and ApexClasses
zip_buffer = sf.mdapi_retrieve(["CustomObject", "ApexClass"])Retrieve specific components by name:
package = {
"CustomObject": ["MyCustomObject__c"],
"ApexClass": ["MyClass", "AnotherClass"],
"ApexTrigger": ["AccountTrigger"]
}
data = sf.mdapi_retrieve(package)- API Limits: Each retrieve counts against Metadata API limits
- Async Operation: Retrieves are asynchronous from Salesforce; sfq handles polling automatically
- Response Format: Results are returned as a dict of file_name with the key and the content as the value.