0

I am developing a Rails app using OmniAuth, OmniAuth-salesforce and this gem: https://github.com/heroku/databasedotcom

I am hardcoding the "client_id" and "client_secret" into my app. Then for each user that authenticates with Saleforce, I am capturing their oauth token, user id, and instance url. With all this, I am creating leads on their behalf.

Everything works if the user is from the same account where I got the "client_id" and "client_secret". However, if I authenticate with a user from another Salesforce instance, I get an "invalid cross reference id" error.

I want my app to be submitting leads for users from many different Salesforce intances. Is this not possible?

Here is my full code:

client = Databasedotcom::Client.new :client_id => SALESFORCE_CLIENT_ID, :client_secret => SALESFORCE_CLIENT_SECRET
client.authenticate :token => user.salesforce_token, :instance_url => user.salesforce_instance_url
client.materialize("Lead")

lead = Lead.new(:FirstName => first_name, :LastName => last_name, :Email => email, 
                :Phone => phone, :OwnerId => user.salesforce_id, :IsConverted => false,
                :IsUnreadByOwner => true, :Company => contact_company)
lead.save

Thanks for any advice!

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Matt Fordham
  • 3,147
  • 10
  • 34
  • 51
  • Whatis the URL you're hitting up for authentication? – Matt Lacey Jan 20 '12 at 23:30
  • @Matt, I am facing exactly same issue, can you tell me how you fixed this issue? I am fetching token using oauth2 gem then using same procedure that you have written – RAJ Apr 10 '13 at 09:41
  • @LaceySnr I am facing same issue and for authentication I am hitting https://login.salesforce.com/services/oauth2/authorize – RAJ Apr 10 '13 at 14:02

1 Answers1

0

The error will be coming from the user.salesforce_id reference you're setting for ownerId, and leads me to think that you are somehow mixing the data up, i.e. you're sending user1 but to the user2's session. I haven't used the gem you mention, but from the code, i can't see how the lead instance is associated with the particular client instance. How does lead.save know to use the client instance you just created ?

Looking more at how materialize("Lead") works, it seems like the Lead.new is always going to create a lead that associated with the first client instance you created, so you'd be trying to send all the leads the first user that you authenticate.

superfell
  • 18,780
  • 4
  • 59
  • 81