Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I’m a sad panda

How to get IDENT_CURRENT from salesforce linked server

I am performing an insert directly to the salesforce linked server and I need to return the last created salesforce id. Currently I am using
SELECT TOP 1 id
FROM SALESFORCE...account
ORDER BY CreatedDate DESC
but this is taking forever to return. I have tried
select * from openquery(salesforce,
'SELECT IDENT_CURRENT(ACCOUNT)')
but this fails with the error
Error translating SQL statement: line 1:29: expecting "from", found ')'

How can I get the last inserted salesforce id in an efficient manner?
1 person has
this question
+1
Reply
  • There are 2 reasons why you cannot get the Id in this manner.

    1. Because salesforce.com is a multi-user the last Account inserted may not of been inserted by you.
    2. The salesforce.com server may have an open UNIT-OF_WORK that is not yet committed and that may contain your inserted record. In this case, your query will return an older inserted record.

    The only reliable way to get Id for your inserted record is to use sf_bulkops with a single row in the load table. After sf_bulkops runs, the Id of the newly inserted record will be in the Id column.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated