• Manfred Linzner
  • NEWBIE
  • 0 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I'm planning to use the Bulk API for a project on Google App Engine. I've started writing some simple test code to create two Tasks using the Bulk API via the Python [salesforce-bulk-api](https://github.com/safarijv/salesforce-bulk-api) library:
from salesforce_bulk_api import SalesforceBulkJob

header = ['WhoId', 'Subject']
messages = [('[...]', 'Test Task 1'),
            ('[...]', 'Test Task 2')]

os.environ['SALESFORCE_INSTANCE'] = '[...]'
os.environ['SALESFORCE_SECURITY_TOKEN'] = access_token

job = SalesforceBulkJob('insert', 'Task')
job.upload(
    header,
    messages
)

results = job.results()
for r in results:
   print('Result ' + str(r))

Executing this code locally works as expected and the two Tasks appear in Salesforce. But running the code on Google App Engine, it fails. The job / batch details are:
<error xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<script/>
<exceptionCode>InvalidSessionId</exceptionCode>
<exceptionMessage>Unable to find session id</exceptionMessage>
</error>

From what I see in the documentation, session ID needs to be sent via header field `X-SFDC-Session` each time. I've checked that and it is set when executing locally as well as via Google App Engine. Headers looking like this:
{ 'Content-Length': '183',
  'Accept-Encoding': 'gzip, deflate',
  'Accept': '*/*',
  'User-Agent': 'python-requests/2.9.1',
  'X-SFDC-Session': u'00D2[...]vBmM',
  'Connection': 'keep-alive',
  'Content-Type': u'application/xml; charset=UTF-8'}

Anyone having tips how to debug / resolve this issue? Thanks!

– Manfred
I'm working on a project where (already sent) emails should be saved to Salesforce and matched with the corresponding Salesforce contact.
Creating new Emails is rather straightforward. For example using the simple_salesforce python library my code looks like this:
 
from simple_salesforce import Salesforce

[…]

sf = Salesforce(instance_url=instance_url, session_id=session_id)
sf.EmailMessage.create(
    {'FromAddress': 'foo@example.com',
     'ToAddress': 'bar@example.com',
     'Subject': 'Email: Fancy Subject', 
     'TextBody': 'lorem ipsum dolor sit amet',  
     'Status': 2
    })

This successfully creates a new EmailMessage but the message is not matched to the contact (assuming bar@example.com is an exisiting contact in Salesfored). This can be seen in numerous places in the Salesforce UI. For example:
It is not part of the contact's activity history
When looking at the Email Message details, the section “Sender and Recipients” is empty
When creating new emails using the Salesforce UI, the association is done correctly. Comparing my EmailMessage objects from the ones generate by Salesforce there is one obvious difference: ActivityId is not set for my objects.
When I'm trying to set ActivityId to a matching Contact ID I receive a Malformed Request Exception INSUFFICIENT_ACCESS_OR_READONLY.

Am I missing something? Is it somehow possible to create those associations using the API?
I'm planning to use the Bulk API for a project on Google App Engine. I've started writing some simple test code to create two Tasks using the Bulk API via the Python [salesforce-bulk-api](https://github.com/safarijv/salesforce-bulk-api) library:
from salesforce_bulk_api import SalesforceBulkJob

header = ['WhoId', 'Subject']
messages = [('[...]', 'Test Task 1'),
            ('[...]', 'Test Task 2')]

os.environ['SALESFORCE_INSTANCE'] = '[...]'
os.environ['SALESFORCE_SECURITY_TOKEN'] = access_token

job = SalesforceBulkJob('insert', 'Task')
job.upload(
    header,
    messages
)

results = job.results()
for r in results:
   print('Result ' + str(r))

Executing this code locally works as expected and the two Tasks appear in Salesforce. But running the code on Google App Engine, it fails. The job / batch details are:
<error xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<script/>
<exceptionCode>InvalidSessionId</exceptionCode>
<exceptionMessage>Unable to find session id</exceptionMessage>
</error>

From what I see in the documentation, session ID needs to be sent via header field `X-SFDC-Session` each time. I've checked that and it is set when executing locally as well as via Google App Engine. Headers looking like this:
{ 'Content-Length': '183',
  'Accept-Encoding': 'gzip, deflate',
  'Accept': '*/*',
  'User-Agent': 'python-requests/2.9.1',
  'X-SFDC-Session': u'00D2[...]vBmM',
  'Connection': 'keep-alive',
  'Content-Type': u'application/xml; charset=UTF-8'}

Anyone having tips how to debug / resolve this issue? Thanks!

– Manfred