Thursday, March 9, 2017

Pull Salesforce Data into AdWords Using Scripts

After my post about importing Zoho CRM data into AdWords, I received a lot of comments about doing something similar for Salesforce. I finally had some time to build a simple class that allows you to query data and objects from your Salesforce instance and use it in your scripts.

First, we will need to set you up with some OAuth credentials, and for that, you need to set up a new connected app in Salesforce. It is in slightly different places in each version, but using the developer version, I was able to find it under Setup > Build > Create > Apps. From there, all the way at the bottom, you can see a section for Connected Apps.
Creating a new connected app

If for some reason you can't find it in your Salesforce instance, your admin may not have given you access to it. Hopefully, they can help you.

After clicking the new button, you will need to fill out a few required fields and then select the option to "Enable Oauth Settings." You will need to enter a callback url but we won't be using it so you can enter any url that starts with https. For "Scopes", I just said "Full Access" but you may have to talk to your Salesforce Admin about that one. We will only be reading from Salesforce so it shouldn't be an issue.
Enabling the OAuth Settings

That's all you need to fill out and you should have a new app created. The important thing here is the "Consumer Key" and the "Consumer Secret" that you will need for the script to connect to your Salesforce instance.
Salesforce Consumer and Secret Keys

The last thing you will need from your Salesforce instance is a security token. You may already have one in which case, you can skip this. But if not, you can reset it under My Settings > Personal > Reset my Security Token. It will email you a new token.
Reset your Security Token

Ok, now we are finally ready to get to the AdWords Scripts code. The following code will set up a new SalesforceAPI object and query the most recent Opportunities that were Close Won so that you can use that revenue in your AdWords account.

It's that simple. If you want to get all the information about a particular object after you query for it, you can use the function getObjectByUrl() and send it the url from the query results. To learn more about the query syntax, check out the Salesforce SOQL documentation.

There are a few caveats for this code. Every Salesforce installation is unique so there really is no way for me to really troubleshoot issues with your specific install. This code was tested on a fresh Salesforce for Developers account so your results may vary. You will probably have more luck contacting your Salesforce Admin than leaving a comment here. Also, you may notice that the code it using the least secure option to log into Salesforce. This code with your username and password will be accessible to all users of your AdWords account, so be careful. It might be better to create a special Salesforce user with very limited permissions for something like this.

If you think this is useful, come let me know at SMX East this week.



  1. So we invented spelling checkers to catch this simple grammar check

  2. Do you need an academic paper at the very same day? Go here and order one page for free.

  3. The capacity it accommodates organizations and its clients to make their own modified Salesforce apparatuses in the cloud with its PaaS arrangement has reinforced the situation of Salesforce in the CRM showcase. salesforce for nonprofits

  4. frases You did really good work. I really appreciate your new and different post. Please guys keep it up and share with us some unique post in the future

  5. Find Latest Job Vacancies and verified Jobs for different categories including drivers, cooks, beauticians, delivery boys, security guards nearby. Apply Now, It's Free!

  6. management and update of business logic, data models, application securities and process automation. It ensured that whatever gaps remained between a programmer and administrator is reduced to a minimum. Salesforce training in Chennai

  7. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks Affordable CRM

  8. This is extremely helpful info!! Very good work. clash of null download

  9. I'm going to share with you the exact ten-step process I take companies through when developing their staff to think and act like business owners who make customers want to buy, buy again, and then go on to tell their friends and family to buy! Salesforce training in Chennai

  10. I love this. It is soo informative. Are you also searching for cheap assignment writing help we are the best solution for you. We are best known for delivering the best services to students without having to break the bank

  11. This comment has been removed by the author.

  12. Téléchargez Android APK et jeux Android gratuitement en ligne sur apksim