Sorry guys I have to update my question to give more clarity on my thoughts/doubts I did research from official documentation from salesforce but didn't quite get anything useful.

I am curious to know

  1. whether we can directly embed the python code into the Apex classes?
  2. Can we call python modules from Apex?
  3. Recently I came to know about the CSP in Salesforce where we can add third-party javascript libraries. Suppose I have a python package published in an online repository. Can I use this package in CSP?
  • Hi, and welcome to SFSE! Please take a moment to read about How to Ask and take the tour. What exactly are you trying to achieve? Please try to be as descriptive as possible so we can provide the best possible answer for your situation. I presume you can cross-compile Python to JavaScript, or even executed with a browser-based Python interpreter, but without more details, it's hard to direct you to a specific solution. You can edit your question to provide more information.
    – sfdcfox
    Mar 9, 2021 at 5:03
  • Thank you so much @sfdcfox for extending the welcome :). I have edited the question. hope now you will get a better understanding of the query.
    – mdanish9
    Mar 9, 2021 at 5:14

2 Answers 2


You cannot run python code on the Salesforce cloud platform (Sales Cloud, Service Cloud, Marketing Cloud, etc...). Salesforce supports Apex (its proprietary language which is similar to Java and is compiled into Java bytecode), Javascript, and that's pretty much the complete list.

Apex code cannot directly call/execute Javascript (or code from any other language, for that matter). The closest you'll get is to make an http callout to a server which in turn executes some other code (which could be javascript, python, php, what-have-you) and returns the result to Salesforce.

Javascript can be used to call methods in Apex, but it requires the Apex code to be specifically set up for that purpose (search documentation for 1) Javascript remoting and 2) @auraEnabled for calling Apex from an Aura component or Lightning Web Component)


you can use Salesforce Functions and python scripts on heroko, aws and ect: https://www.salesforceben.com/get-started-with-salesforce-functions/

  • 3
    Welcome to Salesforce SE! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Sep 12, 2022 at 17:26
  • 1
    last I check it was super expensive compared to AWS.
    – Json
    Apr 18, 2023 at 17:34
  • Salesforce Functions are very expensive, unlikely AWS Lamda or Google Cloud Functions, you have to pre purchase 10's of thousands on a 12 month contract even if your demand is very low... Completely missing one or the benefits of this type of capabilities
    – Robs
    Jun 5, 2023 at 7:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .