Upload CSV to Salesforce using Python: No More Manual Work! Upload Leads to Salesforce with Python

AITECHONE ยท Intermediate ยท๐Ÿ“Š Data Analytics & Business Intelligence ยท12mo ago
Skills: BI Tools53%

About this lesson

๐ŸŒŸ Welcome to AITechone! ๐ŸŒŸ We specialize in online training for cutting-edge technologies, including Salesforce Admin, Development, Lightning Web Components (LWC), AgentForce, Omnistudio, Machine Learning, Python, Data Visualization, and much more! Our programs are enriched with live projects, case studies, and comprehensive study materialsโ€”all designed by real-time industry professionals who are subject matter experts. They share invaluable knowledge to ensure you gain practical, job-ready skills. ๐Ÿ”ง Alongside training, we provide: Resume Screening and Preparation Interview Preparation Remote Support Job Assistance ๐Ÿ” Explore Our Videos to: ๐Ÿš€ Master actionable tips and tricks for Salesforce, Power BI, Integrations, and Einstein Analytics. ๐Ÿ’ก Stay updated on the latest trends in these transformative technologies. ๐Ÿ’ฌ Connect with a vibrant community of tech enthusiasts. ๐ŸŽ“ Enhance your expertise and expand your knowledge. Join us on an exciting journey of education and empowerment! ๐ŸŽฏ Donโ€™t forget to subscribe and turn on notifications so you never miss our latest updates. ๐ŸŒ Get in Touch: Website: www.aitechone.com Email: support@aitechone.com | info@aitechone.com ๐Ÿ“ฑ Follow Us: LinkedIn: https://www.linkedin.com/company/aitechone/ ๐Ÿ“ž Contact Numbers: +918118861309 | +917080814180 (WhatsApp) Empower your career with AITechoneโ€”where knowledge meets opportunity! ๐Ÿš€

Full Transcript

[Music] Hey everyone, welcome back to a tech1.com. My name is Sumit and today I will show you how to integrate Python with Salesforce to upload lead records from a CSV file step by step. Just imagine that you have been assigned a task. you got hundreds of thousands of leads in a CSV file from a marketing event or a Google form and you need them into inside Salesforce pass. So there are two approach either we can tried uh we can upload the leads into the Salesforce by using import option import option directly into Salesforce or we can add the leads one by one. So in today's video I will be going to show you to save your tons of time and what if if I could tell you that we can do this by using just few lines of Python. Now whether you are a Salesforce admin or a developer or a data engineer this is a mustnown automation trick. So in this video I will be going to show you how do we read the leads from a CSV file. How do we connect Python to your Salesforce org using simple authentication and how do we push the data into Salesforce using Salesforce REST API and yes we'll do this step by step even if you are new to Python or Salesforce API. So uh before we proceed uh before we proceed with this uh don't forget to subscribe our YouTube channel and also hit that like button if you are excited. Subscribe for more Salesforce automation tips. So let's dive in into today's video. So here is my requirement. This is my Salesforce org and in this Salesforce org I would like to uh I would like to add new leads to this lead object from a CSV file. So that's a CSV file with uh almost 10 columns and with 25 or 24 records. Actually we got 24 records including the header. So 25 we got 24 records in this file and 10 columns and my objective is to uh upload the data from the CSV file into Salesforce into into this lead object by using simple Python code. So how are we going to do this? So for this we have to prepare few of the steps. First of all and the very first step we have to do is we need to download and install Jupyter notebook. So to know more about how do we install and set up and test the Jupyter notebook in Windows 11. Uh you can check my previous video. I will share the link in the description below. So you can go through that video. you can check it out and uh that will help you that will guide you to set up Jupyter notebook on your Windows 11 environment. So here is my Jupyter notebook. I have already uh installed and run my Jupyter notebook and I'm going to create a new Python file. So I just did a new Python file. If you want you can rename this Python file. Let this Jupyter notebook file open and right now it is not renamed. If you want you can save that. So I can save this Jupyter notebook save notebook and I'm going to rename it as let's say SF or let's say Python to SF integration that's a notebook name. Now here we have to write the codes and what are and how are we going to start what all libraries we need to import we'll be going to do stepbystep implementation. So watch this video till end. If you want to learn something very interesting, please watch this video till end. So step number one, we need to import the libraries. And the very first library which I will be going to import here is import pandas as pd. That's a pandas library. And uh to know more about this pandas library, you can watch my Python tutorial where I have explained more about pandas. Next library which I'm going to import is the Salesforce library. And uh using that Salesforce library we can establish a connection between the Python and Salesforce. And for that the library is from simple Salesforce import Salesforce. Now make sure that you have already installed this libraries by using pip command. So pip pondas and pip install salesforce simple salesforce. So in my case I have installed both the packages and when I execute this when I run this code you can see uh no error is coming that means both the libraries has been imported successfully. Now the next step is we will be going to uh what are we going to do? We will be going to read the data read the uh read the data from CSV into pandas library and this is my CSV file and the location of this CSV file is will be on my desktop. So the location for this CSV file will be my desktop. So I'm going to uh load this CSV file from my desktop into pandas library. So how I'm going to do this? I just write here df is equals to pd dot read csv. The location of the file is the file location is my C drive. So C drive users summit desktop lead here is a file as you can see lead and uh I can copy this slash and the file name is the file name is leads CSV the file name is leads CSV but make sure that we have to pass double backslash otherwise it will not accept that execute and I want to check it. So df dot head. So file added successfully and it display the first five records. DF dot shape DF do.shape it will give so it will tell you 24 rows and 10 columns. Now in my case what I have done I have properly renamed the columns. So make sure the field labels should be same as the labels we have in Salesforce object. So to know more about the field names, field API names. So uh those who are familiar with Salesforce, they know that from where we can get all the field names. So we can navigate to the object properties and from there we can get the field names. So the field names here is first name, last name, company, street, city, postal code, phone, mobile phone, email, website. These are the field labels. So I set the field labels here and the same fields you can find out in lead object like first name is there, last name, company, uh email is there, website is there, we have phone and mobile and uh phone and mobile and street is there, city is there, poster code is there. So we have the fields. So we are going to upload the records into we are going to map the fields to these fields in Salesforce object. Now it's time to stab establish a connection. So in order to establish a connection I need to declare a few of the variables. Salesforce variables. So I just said SF username is equals to here we have to provide username SF password is equal to say a Salesforce password SF token is equal to security token. Now what my username is? So that's my username. This is a Salesforce username. So I copy paste my username here. Uh my password. So admin# 1 2 3 4 5. And please don't try to use the same credentials because it will not allow you to login. So you will not be able to use the same credentials to login to the Salesforce. You have to create you have to set up your own Salesforce account. Now we need the security token. To get the security token, I will get back to the Salesforce object and we'll navigate to settings. And here I will request for reset security token. So I click on reset my security token. Reset security token. And I received an email in my mail box. So that's my security token. I copy this security token and paste it here. That's my username, password, and security token. Now we have to establish a connection and for establishing a connection we'll be using this Salesforce package. So how do we do that? SF is equals to Salesforce SF is equal to Salesforce username username is equal to SF username comma password is equal to SF password comma security _ token is equal to SF token. SF token. And when we run uh if the details are okay, credentials are okay, we will be able to get the connection. See this. So this indicates that the connection has established successfully between say Python and Salesforce. So uh two job has been done successfully. First of all, we have successfully imported the CSV file and also we have successfully established a connected connection between Python and SL code. Now it's time to push the data. So before we push the data, right now the data is in a data frame. We have to convert the data into a dictionary. So I write list of records is equals to BF do.2. So I'm just converting I'm I'm just converting this to dictionary and label this as records and run. If I say list of records. Let's print this. So you can see it's converted into dictionary. See this it's converted into dictionary. Dictionary in the form of key and value pair. And finally we are going to push the data from Python to Salesforce. So how do we do that? We just write SF dot bulk dot lead dot insert and list of records and push this and you can see there is no error. Uh that means the process completed successfully. The process completed successfully. See it's coming. Now we got a message here that the process completed successfully. Okay. Uh you can see status code duplicate detected. So there is one error here because of this uh this record will uh this record will be failed to record failed to create because dup. So you can see this is a very interesting thing. The duplicate detection is also enabled in Salesforce. So if we try to add a duplicate lead, it will not accept that. Now let's go and check verify the lead. Right now it's a 16 records. But when I refresh, I'm able to see you can see the number of records get increases to 39. So that means the new record added successfully. New record inserted successfully in uh lead object using Python from a CSV file. So that's the way we can save our time and we can quickly push the data from uh CSV to Salesforce using Python. And those who are familiar with Python they know that in Python we can do lot of functionalities. If we have to do some data cleansing, data massaging, so that can be done by using data frame by using Python and then we can push. So instead of doing manual operations, we can automate this process by using or we can uh automate this process or basically we can uh transform the data easily by using Python and then push that data into Salesforce or So that's all for the day. That's all for in this video. Uh if you like this video, you can reach out to us on the given numbers. You can contact us for customized training on Python and Salesforce or any kind of project support. Thanks for watching. Have a nice day. Goodbye.

Original Description

๐ŸŒŸ Welcome to AITechone! ๐ŸŒŸ We specialize in online training for cutting-edge technologies, including Salesforce Admin, Development, Lightning Web Components (LWC), AgentForce, Omnistudio, Machine Learning, Python, Data Visualization, and much more! Our programs are enriched with live projects, case studies, and comprehensive study materialsโ€”all designed by real-time industry professionals who are subject matter experts. They share invaluable knowledge to ensure you gain practical, job-ready skills. ๐Ÿ”ง Alongside training, we provide: Resume Screening and Preparation Interview Preparation Remote Support Job Assistance ๐Ÿ” Explore Our Videos to: ๐Ÿš€ Master actionable tips and tricks for Salesforce, Power BI, Integrations, and Einstein Analytics. ๐Ÿ’ก Stay updated on the latest trends in these transformative technologies. ๐Ÿ’ฌ Connect with a vibrant community of tech enthusiasts. ๐ŸŽ“ Enhance your expertise and expand your knowledge. Join us on an exciting journey of education and empowerment! ๐ŸŽฏ Donโ€™t forget to subscribe and turn on notifications so you never miss our latest updates. ๐ŸŒ Get in Touch: Website: www.aitechone.com Email: support@aitechone.com | info@aitechone.com ๐Ÿ“ฑ Follow Us: LinkedIn: https://www.linkedin.com/company/aitechone/ ๐Ÿ“ž Contact Numbers: +918118861309 | +917080814180 (WhatsApp) Empower your career with AITechoneโ€”where knowledge meets opportunity! ๐Ÿš€
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Related Reads

๐Ÿ“ฐ
Star, Snowflake, or Galaxy? Choosing Your Data Warehouse Schema
Learn how to choose the right data warehouse schema for your organization, including Star, Snowflake, and Galaxy schemas, to optimize data analysis and reporting
Dev.to ยท grace wambua
๐Ÿ“ฐ
DaDaDa: A Dataset for Data Pricing in Data Marketplaces
Learn how to price data products in data marketplaces using the DaDaDa dataset and improve your data pricing strategies
ArXiv cs.AI
๐Ÿ“ฐ
I Tried to Predict the World Cup. What I Learned Had Nothing to Do with Football.
A data engineer's attempt to predict the World Cup using statistical modeling reveals valuable lessons about uncertainty and problem-solving in real-world applications.
Medium ยท Data Science
๐Ÿ“ฐ
Your Company Does Not Need More Dashboards. It Needs Better Decisions.
Companies often mistakenly focus on creating more dashboards instead of improving decision-making processes, which is crucial for business success
Medium ยท AI
Up next
Modified Distribution Method (MODI) In Transportation Problem /Operations Research/Statistics
EZIKAN ACADEMY
Watch โ†’