我想通過使用SOAP API來編程禁用用戶。我怎樣才能做到這一點?我使用的是合作伙伴API,我有開發者版。我管理用戶保留設置。我已經通過this鏈接。我正在尋找可以幫助我禁用/停用用戶的代碼。如何通過SOAP API禁用/停用SalesForce用戶?
這是我的代碼:
import com.sforce.soap.partner.Connector;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
public class DeactivateUser {
public static void main(String[] args) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername("[email protected]");
config.setPassword("sjjhggrhgfhgffjdgj");
PartnerConnection connection = null;
try {
connection = Connector.newConnection(config);
QueryResult queryResults = connection.query("SELECT Username, IsActive from User");
if (queryResults.getSize() > 0) {
for (SObject s : queryResults.getRecords()) {
if(s.getField("Username").equals("[email protected]")){
System.out.println("Username: " + s.getField("Username"));
s.setField("IsActive", false);
}
System.out.println("Username: " + s.getField("Username") + " IsActive: " + s.getField("IsActive"));
}
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}
}
這是輸出:
Username: [email protected] IsActive: true
Username: [email protected] IsActive: false
Username: [email protected]
Username: [email protected] IsActive: false
然而,在UI,當我去我的名字>設置>管理用戶>用戶,它總是表現出 '主動'複選框爲用戶[email protected]選擇:-(
我覺得你忘了在** set **'IsActive'之後調用'connection.update',閱讀這個> http://www.salesforce.com/us/developer/docs/api/index_Left。 htm#StartTopic = Content/sforce_api_calls_update.htm –
感謝Martin Borthiry指出缺少的內容。我會仔細看看的。 – waprau