2017-11-28 3 views
1

저는 Python Simple-Salesforce를 사용하여 SOQL을 통해 데이터를 쿼리합니다. "SELECT *"는 SOQL 구문에서 지원되지 않으므로 SELECT 문에 삽입 할 모든 필드의 문자열 목록을 모으는 Python 스크립트를 만들고 싶습니다. 다음은 계정 객체를 설명하는 방법입니다.Python Simple Salesforce 모든 필드 선택

from simple_salesforce import Salesforce 
from simple_salesforce import SFType 

#(credentials hidden) 
sf = Salesforce(username=username, password=password, 
       security_token=security_token, sandbox=True, 
       client_id='mwheeler App') 

desc = sf.Account.describe() 
print(desc) 

아래에 표시된 주문 된 사전의 문자열 목록에 필드 이름을 어떻게 추출해야합니까?

DESC :

OrderedDict ([('actionOverrides'[]),() 'activateable'거짓 ('childRelationships'[OrderedDict ([('cascadeDelete'거짓) (('junctionReferenceTo', []), ('관계 아이디', '계정' (')', ''(''), (''), ''(''), '' '' '' '' '' '' '' AccountId '), ......

모든 필드를 선택하려면 문자열 목록을 사용합니다.

query = sf.query_all("SELECT string_list FROM Account") 

답변

0

이 파이썬 라이브러리 호출을 설명은 여기에서 볼 수있다 : 내가 당신이라면 나는 그들이 처음에 정렬 된 사전을 가지고 어떻게 다시 추적 할

https://github.com/simple-salesforce/simple-salesforce/blob/d2ba65e977730ce987ca7d3c38e0f8965d99eec1/simple_salesforce/api.py#L184

.

당신은이 라인에서 볼 수 있습니다

https://github.com/simple-salesforce/simple-salesforce/blob/d2ba65e977730ce987ca7d3c38e0f8965d99eec1/simple_salesforce/api.py#L187

그들이 여기에서 기본 URL을 사용하는 것이 :

https://github.com/simple-salesforce/simple-salesforce/blob/d2ba65e977730ce987ca7d3c38e0f8965d99eec1/simple_salesforce/api.py#L173

당신이 당신의 워크 벤치에 같은 전화를 걸 수 있다는 데 :

https://workbench.developerforce.com/login.php

그런 다음 사전을 통과하는 방법에 대한 몇 가지 유용한 예제를 찾을 수있는 간단한 구글 검색으로

, 여기에 몇 가지 :

How to do this - python dictionary traverse and search

Loop through all nested dictionary values?

Walking/iterating over a nested dictionary of arbitrary depth (the dictionary represents a directory tree)

을만큼 당신이 알고 당신이 사전을 탐색하기 위해 찾고있는 것은 다소 쉬워야합니다.

모든 필드를 쿼리 한 경험으로 볼 때 FFLib과 같은 엔터프라이즈 프레임 워크에는 위와 같은 경고가 표시되지만 일부 개체는 하나의 SOQL 쿼리에 모든 필드를 포함하도록 설계되지 않았습니다.

는 SOQL 제한이 페이지를 참조하십시오 :이 도움이

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_limits.htm

희망을.

0

필드 이름을 아래에 표시된 주문 된 사전에서 문자열 목록으로 추출해야하는 방법은 무엇입니까?

나는 질문이 얼마 전에 게시 된 인식 솔루션

from simple_salesforce import Salesforce 

#(credentials hidden) 
sf = Salesforce(username=username, password=password, 
       security_token=security_token, sandbox=True, 
       client_id='mwheeler App') 

desc = sf.Account.describe() 

# Below is what you need 
field_names = [field['name'] for field in desc['fields']] 
soql = "SELECT {} FROM Account".format(','.join(field_names)) 
results = sf.query_all(soql) 

# Alternative method to retrieve results 
# I don't have any recommendation which to use 
results = sf.bulk.Account.query(soql) 

, 그냥 완벽한 솔루션을 갖고 싶어를 포함하도록 코드를 확장했습니다.

관련 문제