simple-salesforce | A very simple Salesforce.com REST API client for Python | REST library
kandi X-RAY | simple-salesforce Summary
kandi X-RAY | simple-salesforce Summary
A very simple Salesforce.com REST API client for Python
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Login to Salesforce .
- Checks the deployment status .
- Bulk operation .
- Login to a user .
- Queries the Salesforce API .
- Initialize the session .
- Quote a SOQL value .
- Login to a portal .
- Get a specific customer id
- Fetches metadata for the specified collection .
simple-salesforce Key Features
simple-salesforce Examples and Code Snippets
api_names = ["Account", "Contact", "Campaign"]
for obj in Api_names:
desc = getattr(sf, obj).describe()
SELECT AccEmail__c,
(select custid__c from Backends__r)
from Account
where Id in (select account__c from Backend__c where custid__c LIKE '%CUST%')
SELECT AccEmail__c,
(select custid__c from Backends__r whe
task_result = sf.query(format_soql(
"SELECT Id, WhoId FROM Task WHERE Id = {task_id}",
task_id=task_id))
max_date = '2020-08-10T17:41:29' # in prod, pull this data from BigQuery
max_date = max_date + "Z"
SF_QUERY = ("""
SELECT Id,
CreatedDate
FROM Opportunity
WHERE CreatedDate > %s
""" % max_date)
df = SFType(self.obj, self.sf.session_id, self.sf.sf_instance)
data = df.describe()
columns = [x['name'] for x in data['fields']]
return columns
object_to_export = ['Opportunity','Asset']
def sf_login():
"""
Purpose: This function is designed to validate your Salesforce credentials and
create/return an instance or session.
Note: If we have already signed in, this wil
import datetime
yesterday = datetime.datetime.now() + datetime.timedelta(days=-1)
sf_data = sf.query_all("SELECT ID, Name FROM Opportunity where probability > 0 AND CreatedDate > '%s' AND AdPoint_Id__c <> NULL ORDER BY AdPoint_
SELECT name, Email FROM Contact WHERE LastName = 'Chen'
Community Discussions
Trending Discussions on simple-salesforce
QUESTION
I am currently using the simple-salesforce
library to retrieve data from Salesforce, using the token method.
ANSWER
Answered 2021-Apr-22 at 19:51I think MFA will be required only for users using the standard login - from the Help article mentioned above, it says: "All internal users who log in to Salesforce products* (including partner solutions) through the user interface must use MFA. To ensure that MFA is enabled for all your Salesforce users, you can turn it on directly in your Salesforce products or use your SSO provider's MFA service."
But you are auth'ing via the API, right?
Can you share an error message or screenshot?
Typically API auths happen via a connected app configured in the org, and as I recall, the connected app has a setting requiring MFA ... This help article goes into greater detail about where MFA is required (which login approaches)
Could it be that you are running into the standard user verification challenge whenever salesforce sees an auth for a user from a new network location. You can disable that here by setting an IP address range.
QUESTION
I am trying to bulk upsert records into Salesforce using the simple-salesforce
Python library.
I have a list of dictionaries called categories
with the format [{'FooNumber': '001', 'Category': 'A'}, {'FooNumber': '002', 'Category': 'B'}, {'FooNumber': '003', 'Category': 'C'}...]
When I try upsert
with one record at a time it works:
sf.Foo.upsert('FooNumber/001', {'Category': 'A'})
According to the documentation, the following bulk upsert code should work:
sf.bulk.Foo.upsert(scores, 'FooNumber', batch_size=1000)
But, I get the following error:
TypeError: upsert() got an unexpected keyword argument 'batch_size'
What is wrong with bulk upsert?
Note: I cannot make the code reproducible since I am working with private data.
...ANSWER
Answered 2020-Oct-24 at 16:11Most likely, you need to update your simple_salesforce
. This capability was added in simple_salesforce
1.1.0, the latest release.
QUESTION
I'm trying to select all records from the OPPORTUNITY object that are greater than a variable DateTime. However, I can't figure out how. This is in a Python script using the simple_salesforce package. I believe the issue is either that I am missing the millisecond and +0000 timezone specification in my "max_date" parameter, which I retrieve from a BigQuery table, or that I'm not passing in my max_date parameter as a correct datatype.
My example code that does not work:
...ANSWER
Answered 2020-Aug-12 at 17:13The solution is to append a "Z", short for Zulu time, which indicates UTC, to the end of my datetime string. The dynamic variable %s should not have quotes. Example:
QUESTION
I'm attempting to make SOQL queries to the Salesforce API using the Python salesforce_api and simple-salesforce modules. I had been making these requests with a client object:
...ANSWER
Answered 2020-Jun-24 at 23:11Uh. It's doable but it's an art. I'll try to write it up but you should have a look at "Identity and Access Management" Salesforce certification, study guides etc. Try also asking at salesforce.stackexchange.com, might get better answers and Okta specialists.
I don't know if there's pure server-side access to Okta where you'd provide OAuth2 client, secret, username and password and it'd be silently passed to login.
If your app is a proper web application that needs human to operate - you can still make it work with SSO. You'd have to read about OAuth2 in general (you saw it on the web, all the "login with Google/Facebook/LinkedIn/Twitter/..." buttons) and then implement something like this or this. Human starts in your app, gets redirected to SF to enter username and password (you don't see password and you don't care whether he encountered normal SF login page or some SSO), on success he/she is redirected back and you receive info that'll let you obtain session id (sometimes called access token). Once you have access token you can make queries etc, it's just a matter of passing it as HTPP Authorization Bearer header (simple-salesforce docs mention session id at top of the examples).
Look, I know what I've written doesn't make much sense. Download Data Loader and try to use it. You might have to make it use custom domain on login but there is a way for it to still work, even though you have SSO enforced. Your goal would be to build similar app to how Data Loader does it. This might help a bit: https://stackoverflow.com/a/61820476/313628
If you need a true backend integration without human involved... tricky. That might be a management problem though. They should not enforce SSO on everybody. When Okta's down you're locked out of the org, no way to disable SSO. You should have a backup plan, some service account(s) that don't have SSO enforced. They might have crazy password requirements, maybe login only from office IP address, whatever. It's not a good idea to enforce SSO on everybody.
https://help.salesforce.com/articleView?id=sso_tips.htm
We recommend that you don’t enable SSO for Salesforce admins. If your Salesforce admins are SSO users and your SSO server has an outage, they have no way to log in to Salesforce. Make sure that Salesforce admins can log in to Salesforce so that they can disable SSO if problems occur.
(If you have a web app and it's embedded as Canvas in SF - there's another clean way to have the session id passed to you. Again - this works only if you have a human rather than backend integration)
QUESTION
I am trying to build a docker image with the following requirement.txt file but when I call my python function, there is a part that calls to a redshift database to perform query and ectract data, then I get an error :
ImportError: /usr/local/lib/python2.7/site-packages/psycopg2/.libs/libresolv-2-c4c53def.5.so: symbol __res_maybe_init version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference
...ANSWER
Answered 2020-Apr-29 at 22:20You should update psycopg2
to atleast 2.7.3.1
avoid compatibility issues with glibc 2.26
from release notes
Dropped libresolv from wheel package to avoid incompatibility with glibc 2.26 (wheels ticket #2).
QUESTION
I am using the python3.7.2 module simple-salesforce==0.74.2
and I am having trouble trying to establish a connection to my salesforce sandbox. I can login to the salesforce production with the same credentials just fine like so:
ANSWER
Answered 2019-Apr-11 at 17:53Solved. Set domain='test'
and generate a new token under your sandbox account
QUESTION
I'm currently using simple-salesforce to return some rows and write to a csv file with column headers. However, if the row count is 0 e.g. 'select Id from Lead limit 0' I just get the following response
OrderedDict([('totalSize', 0), ('done', True), ('records', [])])
Is there a way of still getting the column headers even if there are zero rows returned in the query.
Basically I need to create the csv with headers even if there are 0 rows
...ANSWER
Answered 2020-Feb-11 at 22:25Unfortunately, there's not. A query doesn't really return headers as such at all (unless you use the Bulk API); in just returns a list of records composed of key-value pairs.
The usual pattern is that you generate a query from a list of fields, and that list of fields becomes your column headers. For example,
QUESTION
I am using simpleSalesforce library for python to query SalesForce.
I am looking at two different object in SalesForce: Account and Opportunity (parent-child). There is an accountId inside the opportunity object.
I am trying to perform an inner join between the two and select the results (fields from both objects). a normal SQL statement would look like this:
...ANSWER
Answered 2020-Jan-29 at 13:54A couple notes about SOQL:
- No aliases allowed
- No explicit joins allowed
But with that in mind, it's still possible to get the outcome you want by directly using the desired fields names as an "attribute" of the object relationship. Example:
SELECT account.Name, Name, StageName FROM Opportunity
Which will grab the related account name, the opportunity name, and the opportunity stage name in one query.
As long as the field on your base object is of a type Lookup
or Master-Detail
, you can use this type of relationship. In the case of custom fields, you switch the __c
over to __r
though.
Example:
Opportunity has a relationship to custom object Address__c
and we want to know what city & country these opportunities are in:
SELECT Address__r.Country__c, Address__r.City__c,Name, StageName from Opportunity
QUESTION
We currently use TFS as ticket system for Support Tickets. I wrote the code below so that a user can dump an email into a folder and then access a webpage to submit a form and create a TFS Support Ticket and assign it to the user. The goal is to have the emails removed from the folder after the form has been submitted and the Support Ticket has been created.
The problem I'm running into is that when I try to remove the emails after the TFS Support Ticket has been created it removes some of the files but then gets stuck on the last one and display the following error message.
"PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\b4bw3\Documents\Python\simple-salesforce\Email\Delete_Me1.msg'"
If I remove the portion of code that creates the TFS ticket then it will rename the email and remove it after it is done as expected. It appears that the hang up is with TFS. I'm stumped and need help.
Any thoughts? btw, this is my first attempt at Python, so be gentle. :)
'''
...ANSWER
Answered 2020-Jan-16 at 15:55It appears this is a current bug for the msg-extractor. I found the link below that explains in detail.
https://github.com/mattgwwalker/msg-extractor/issues/85?_pjax=%23js-repo-pjax-container
I added the following code line to the end of my method and it works like a charm.
QUESTION
I am using Python 3.6 with Django 1.11. My Back-end DB is Salesforce.
I am trying to save date field in Salesforce which is accepted from user in the form of String
...ANSWER
Answered 2017-Nov-09 at 09:56According to this link, one should pass dates as UTC datetime, so:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install simple-salesforce
You can use simple-salesforce like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page