所以我试图使用Salesforce API查找用户使用他们的ID。但我遇到了如何解决的问题。目前我有:
private static HashMap<String, id> getUserIdByName = new HashMap<String, id>();
//private String id = null;
public static String getUserIdByName(final String profileName) throws ConnectionException {
if (profileName == null && profileName.isEmpty()) {
throw new IllegalArgumentException("Something is wrong with the profile name");
}
if (getUserIdByName.containsKey(profileName)) {
return getUserIdByName.get(profileName);
} else {
try {
id profileId = GET_USER_ID_BY_NAME;
getUserIdByName.put(profileName, profileId);
return profileId; //private static final String GET_USER_ID_BY_NAME = "SELECT id From Profile WHERE Name='%s'"; //%s
} catch (QueryException qex) {
System.out.print("Error" + qex.getMessage());
throw new IllegalArgumentException("Error with the query!");
}
return null;
}
}
目前这就是我所拥有的,我不能为我的生活找出为什么我&#34; id&#34;无法解决。我想我的大部分方法都写得正确,但我错了。谢谢你的帮助!
我一直在研究的另一个版本是:
public String getUserIdByName(final String userId) throws ConnectionException {
String id = null;
final String sql = String.format(GET_USER_ID_BY_NAME, StringEscapeUtils.escapeSql(userId));
final QueryResult queryResult = partnerConnection.query(sql);
for(final SObject User : queryResult.getRecords()) {
id = User.getId();
System.out.println(User);
}
return id;
}
我对它们使用的查询是:SELECT id From Profile WHERE Name =&#39;%s&#39;&#34;
我对第二个更有信心,但我仍然无法获得正确的ID。