英文:
Salesforce object is not accessible via API, but working via UI
问题
我可以通过用户界面使用类似于以下URL的方式通过Id访问我的对象:lightning/r/Account/0061n00000b5pEdAAI/view
,但我无法通过相同的用户使用API
获取它:
sf_client.query_all(f"""SELECT Id, Name FROM Account where Id='0061n00000b5pEdAAI'""")
而且这并不是所有对象都出现的情况。每隔3个对象中的一个对象是不可用的。我检查了权限并按照此指南中的说明设置了对所有对象的访问权限:
英文:
I can access my object by Id via user interface by using URL like lightning/r/Account/0061n00000b5pEdAAI/view
, but I'm not able to get it via API
with same user:
sf_client.query_all(f"""SELECT Id, Name FROM Account where Id='0061n00000b5pEdAAI'""")
And this happens not with all objects. Like every 3rd object is not available. I checked permissions and set access to all like in this guide:
答案1
得分: 1
你确定你正在访问相同的组织和相同的用户吗?听起来像是在沙盒环境中,一些数据从生产环境复制过来,一些数据不同步... 你能前往目标组织,找到那个用户,滚动到登录历史并查看今天的登录记录,从你的Python程序中(带有可以与你程序中使用的客户端ID/密钥匹配的应用程序名称)...
你正在使用简单的Salesforce,对吗?尝试获取登录调用返回的会话ID(也称为访问令牌)(https://github.com/simple-salesforce/simple-salesforce#readme,滚动到“附加功能”部分)。它看起来像这样 00D0E000000ABCDabc!randomgibberishhere
。!
前面的部分是组织ID。你可以将其与“设置” -> “公司信息”或(在生产环境中)“设置” -> “沙盒”进行比较,以确保你正在访问正确的组织。用户名也是一个线索... 如果真的发生了这种情况,这将是一个令人尴尬的错误,但我们都曾经历过。
当你在开发者控制台中运行相同的查询时会发生什么(UI右上角的齿轮/齿轮图标)?
当你使用原始的REST访问或原始查询时会发生什么,例如使用Workbench的REST资源管理器:https://workbench.developerforce.com/login.php
/services/data/v58.0/query/?q=SELECT Id, Name FROM Account where Id='0061n00000b5pEdAAI'
/services/data/v58.0/sobjects/Account/0061n00000b5pEdAAI
英文:
You're sure you're hitting the same org, same user? Sounds like sandbox where some data was copied over from prod, some is out of sync... Can you go to target org, find that user, scroll down to login history and see logins today, from your Python program (with Application name that can be matched to client id/secret you used in your program)...
You're using simple salesforce, right? try to grab session id (also known as access token) returned by login call (https://github.com/simple-salesforce/simple-salesforce#readme, scroll down to "Additional Features"). It'll look like 00D0E000000ABCDabc!randomgibberishhere
. The part before !
is org id. You can compare it with Setup -> Company Information or (in prod) Setup -> Sandboxes to make sure you're hitting right org. Username would be another giveaway... It's an embarassing mistake if it's really what happened but we've all been there.
What happens when you run same query in Developer Console (cog/gear icon in upper right corner in UI)?
What happens when you issue raw REST access or raw query for example with Workbench's REST explorer: https://workbench.developerforce.com/login.php
/services/data/v58.0/query/?q=SELECT Id, Name FROM Account where Id='0061n00000b5pEdAAI'
/services/data/v58.0/sobjects/Account/0061n00000b5pEdAAI
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论