简体   繁体   English

Salesforce SOQL 获取分配给登录用户的所有帐户

[英]Salesforce SOQL to fetch all the accounts assigned to the logged in user

I have the accessToken of the logged in user and currently my query looks like below我有登录用户的 accessToken,目前我的查询如下所示

https://xxx.salesforce.com/services/data/v45.0/query?q=SELECT Id,Name,Industry,Ownership,AnnualRevenue,NumberOfEmployees,Phone,Website FROM account ORDER BY LastModifiedDate DESC LIMIT 10

The above query will return last 10 modified accounts that the loggedin user has access to.上述查询将返回登录用户有权访问的最后 10 个修改帐户。 What I want is to get only those accounts that are assigned to the logged in user.我想要的是只获取分配给登录用户的那些帐户。

You need a query similar to您需要一个类似于

SELECT Id, Name
FROM Account
WHERE OwnerId = '005...'
ORDER BY LastModifiedDate DESC 
LIMIT 10

All users' ids in all SF instances in the world start with 005.全球所有 SF 实例中所有用户的 id 都以 005 开头。

You can get the user id from the login success response.您可以从登录成功响应中获取用户 ID。 Which OAuth2 flow you've used?您使用过哪种 OAuth2 流程? https://help.salesforce.com/articleView?id=sf.remoteaccess_oauth_user_agent_flow.htm&type=5 ? https://help.salesforce.com/articleView?id=sf.remoteaccess_oauth_user_agent_flow.htm&type=5

In that example the user's id is hidden in the OAuth "id" field (identity, service that returns some info about the user. name, email, preferred language, locale, timezone...)在该示例中,用户的 id 隐藏在 OAuth“id”字段中(身份、返回有关用户的一些信息的服务。名称、email、首选语言、区域设置、时区......)

https://www.customercontactinfo.com/user_callback.jsp#
access_token=00Dx0000000BV7z%21AR8AQBM8J_xr9kLqmZIRyQxZgLcM4HVi41aGtW0qW3JCzf5xd
TGGGSoVim8FfJkZEqxbjaFbberKGk8v8AnYrvChG4qJbQo8&
refresh_token=5Aep8614iLM.Dq661ePDmPEgaAW9Oh_L3JKkDpB4xReb54_pZfVti1dPEk8aimw4Hr9ne7VXXVSIQ%3D%3D&
instance_url=https://yourInstance.salesforce.com&
id=https://login.salesforce.com%2Fid%2F00Dx0000000BV7z%2F005x00000012Q9P&
issued_at=1278448101416&
signature=miQQ1J4sdMPiduBsvyRYPCDozqhe43KRc1i9LmZHR70%3D&
scope=id+api+refresh_token&
token_type=Bearer&
state=mystate

It's bit hard to see but if you would receive this response you need to extract the 005x00000012Q9P part.有点难看,但如果您收到此响应,您需要提取005x00000012Q9P部分。 If you don't trust parsing that url - well, call that "id" endpoint.如果您不信任解析该 url - 好吧,称之为“id”端点。 See https://salesforce.stackexchange.com/q/11728/799 for response format and some more ideas.有关响应格式和更多想法,请参阅https://salesforce.stackexchange.com/q/11728/799

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM