We’re Heading to CNX ’25. Let's Meet in Chicago! Join HIC at Salesforce Connections'25 for conversations, collaboration, and co-creation.

If you’re looking to integrate Salesforce with a Python web application, Flask, and simple-salesforce are two powerful tools that can help you get the job done quickly and easily.

 

In this blog post, we’ll show you how to set up a Flask application that connects to Salesforce using simple Salesforce and create a simple form that allows users to create orders in Salesforce.

 

Before we get started, let’s briefly review what Flask and simple Salesforce are and why they are useful for integrating with Salesforce

What is Flask and Simple Salesforce

Flask is a lightweight web framework for Python that allows you to quickly create web applications without getting bogged down in the details of HTTP requests and responses. Simple-Salesforce is a Python library that provides a simple interface to the Salesforce API, allowing you to easily create, read, update, and delete Salesforce objects from your Python code.

 

Setting Up the Environment

To get started, you’ll need to install Flask and simple Salesforce. You can do this using pip, the Python package manager:

pip install flask simple-salesforce

You’ll also need to create a Salesforce account if you don’t already have one, and generate a security token that you can use to authenticate with the Salesforce API.

 

You can get your security token by clicking on your Salesforce profile then Settings –> My Personal Information –> Reset My Security Token.

 

Once you have these in place, you’re ready to start building your Flask application.

Creating the Flask App

To create the Flask app, you’ll need to:

 

Create a new folder in your development environment. In that folder create two folders templates and static.

 

In the parent folder create a Python file in which we will be writing code for Flask and simple Salesforce.

 
1 1 300x225 1

your project structure should look like this.

 

In “myapp.py” use this code:

In this code :

 

When a POST request is received, the application retrieves data from the submitted form (account name, effective date, and status) and uses the Salesforce API to perform a query to find the account ID based on the account name.

 

If the query returns no results (i.e., there is no existing account with the given name), the application creates a new account with the given name and then creates a new order associated with that account. If the query returns one or more results (i.e., there is an existing account with the given name), the application creates a new order associated with each account returned by the query.

 

Now create a front-end form to take the information which is required to create an account and an order. *Create this HTML file *“orderForm.html” inside templates folder.

 

You can also use some CSS to make the form look presentable

So from this now we have an HTML form that looks like this. You can modify it to your liking with more CSS.

2 768x257 1

Testing the App

Now let’s test the app by creating some orders

3 768x261 1

Here we created an order for Account Tesla which was already created and we can see if that order got created in our salesforce org or not.

4 768x122 1

The order got successfully created for this Account.

 

Now let’s try to make an order for an account that does not exist.

5 768x235 1

In this, we can see when we try to make an order for an account Honda. In retrieved records, we got no records because it does not exist in our salesforce org.

 

So it should have created an account, Honda. And then created an order for that account.

6 768x134 1
7 768x118 1

And we got the expected result as it created the account Honda and an order for that.

 

Congratulations! You have successfully created a sales order in Salesforce using a Flask app and Simple Salesforce.

Conclusion

In conclusion, this blog demonstrated a simple yet powerful way to integrate Flask with Salesforce using the Simple Salesforce library. We were able to create a web form that allowed users to create an order in Salesforce, all with just a few lines of code.

 

Try out the Salesforce solution for yourself and be sure to share your valuable suggestions with us. Until the next one, stay connected!

Related Articles
Expert Guide On Nominal XIRR Calculation Using LWC in Salesforce

When building financial tools within Salesforce, handling irregular cash flows with precision is a must. Whether you’re developing investment trackers, portfolio performance dashboards, or funding monitors, calculating Nominal XIRR (Extended Internal Rate of Return) becomes essential. In this blog, you’ll learn how to build a Lightning Web Component (LWC) in Salesforce that calculates Nominal XIRR […]

Read More
Beginners Guide to Making Your LWC Component Multilingual

If you’re wondering how to make your LWC component multilingual, you’re already ahead of the curve. Global users expect content in their native language, and Salesforce gives you the tools to deliver exactly that. With Custom Labels and the Translation Workbench, you can easily localize your Lightning Web Components without touching a single line of […]

Read More
Hands-On Guide Building a Drag-and-Drop Form Builder Using Lightning Web Components

Drag-and-drop interfaces are a user experience staple, and when paired with the power of Lightning Web Components (LWC), they unlock dynamic, highly interactive Salesforce components. In this blog post, we’ll walk you through how to build a custom drag-and-drop form builder in LWC. Users can drag form fields like text inputs and dropdowns into a […]

Read More
Please Make Blog Banner How to Create an Agentforce Enabled Scratch Org in Salesforce 100 1

Setting up an Agentforce-enabled scratch org is the most important step for developers who want to experiment with AI features such as Prompt Builder and Einstein GPT. Whether you’re developing the next generation CRM software or experimenting with how generative AI may improve user experience, a scratch org equipped with Agentforce is your playground. Follow […]

Read More
Step-by-Step Guide to Enhance Your LWC Development Workflow with the Logger API

Are you looking to streamline your LWC development workflow but confused about how to do it? Then you are in the right place. The Salesforce Logger API is a powerful tool that helps you monitor, debug, and improve code quality in real time.  This step-by-step guide walks you through how to set it up and […]

Read More
Enhancing Your Salesforce Experience with a Custom Activity Component

In today’s fast-paced business landscape, productivity hinges on streamlined workflows and intuitive interfaces. While Salesforce offers robust activity tracking capabilities, sometimes the standard components fall short of specific organizational needs.  That’s where a Custom Activity Component comes in—designed to tailor your activity management experience, boost user efficiency, and provide deeper insights into customer interactions. In […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818