function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
waprauwaprau 

How to disable/deactivate a User through SOAP API?

I want to disable a User programmetically by using SOAP API. How can I do that? I am using Partner API and I have developer edition. I have manage users persmissions set. I have gone through this link. I am looking for code which can help me disable/deactivate a User.

 

This is my code:

 

    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("waprau@waprau.com");
    		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("abcd@pqrs.com")){
						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();
    		}
    	}
    }

 

This is output:

 

    Username: waprau@waprau.com IsActive: true
    Username: jsmith@ymail.net IsActive: false
    Username: abcd@pqrs.com
    Username: abcd@pqrs.com IsActive: false

 

However in UI when I go to My Name > Setup > Manage Users > Users, it always show 'Active' check box for user abcd@pqrs.com selected :-(

Thanks,
Wap Rau