Title: Extended Response Time with simple_salesforce Library's upsert method

25 views Asked by At

Problem Statement:

I'm encountering prolonged response times exceeding 30 seconds while using the simple_salesforce library to perform upsert operations in batches using the bulk functionality. The upsert method seems to take an extended duration to process, affecting the overall performance of my application.

from simple_salesforce import Salesforce
import requests
import json

# Salesforce credentials
USERNAME = 'xxx'
PASSWORD = 'yyy'
CLIENT_ID = 'zzzzzzzzz'
CLIENT_SECRET = 'a1b1c1'
token_url = ''



payload = {
            'grant_type': 'password',
            'client_id': CLIENT_ID,
            'client_secret': CLIENT_SECRET,
            'username': USERNAME,
            'password': PASSWORD
        }
try:
    print('Invoking token endpoint')
    r = requests.post(
        token_url,
        headers={"Content-Type":"application/x-www-form-urlencoded"}, data=payload)

    body = r.json()
    token = body['access_token']
    print("session Id:",token)
    
    sf = Salesforce(instance_url=instance_url, session_id=token)   
    

    data = "[{"id": "1de4f46gfdvznasdsa","name": "Test-1"},{"id": "1gfsdvznasdsw324a1","name": "Test-2"},{"id": "46gfdvznasdsa2eref23","name": "Test-3"}]"
    response = sf.bulk.Account.upsert(data, 'Account')
    print("Response= ",response)   
        
    
        
except requests.exceptions.RequestException as e:
    print("Error in request:", str(e))
    
except Exception as e:
    print('Error: ', str(e))
                    

Environment Details: Python version: 3.10 simple_salesforce library version:1.12.5

Efforts Made:

1. I tried to optimize code using bulk query and operater but getting same response.
2. I tried with request package and working fine using api response time is appropriate

But I want to know why its taking prolonged time response while using simple-salesforce module.

Request:

I'm seeking guidance on optimizing the upsert process or suggestions to improve the performance while using the simple_salesforce library for bulk operations.

Thank you for any insights or assistance.

0

There are 0 answers