Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:03:16+00:00 2026-06-11T17:03:16+00:00

I want to disable a User programmetically by using SOAP API. How can I

  • 0

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 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:03:18+00:00Added an answer on June 11, 2026 at 5:03 pm

    It doesn’t look like you’re actually sending the update back to Salesforce – you’re just setting IsActive to false locally. You will need to use a call to PartnerConnection.update(SObject[] sObjects) in order for Salesforce to reflect your changes, like so:

    try {
        connection = Connector.newConnection(config);
        QueryResult queryResults = connection.query("SELECT Id, Username, IsActive from User");
    
        if ( queryResults.getSize() > 0 ) {
            // keep track of which records you want to update with an ArrayList
            ArrayList<SObject> updateObjects = new ArrayList<SObject>();
            for (SObject s : queryResults.getRecords()) {
                if ( s.getField("Username").equals("abcd@pqrs.com") ){
                    System.out.println("Username: " + s.getField("Username"));
                    s.setField("Id", null);
                    s.setField("IsActive", false);
                }
                updateObjects.add(s);    // if you want to update all records...if not, put this in a conditional statement
                System.out.println("Username: " + s.getField("Username") + " IsActive: " + s.getField("IsActive"));
            }
            // make the update call to Salesforce and then process the SaveResults returned
            SaveResult[] saveResults = connection.update(updateObjects.toArray(new SObject[updateObjects.size()]));
            for ( int i = 0; i < saveResults.length; i++ ) {
                if ( saveResults[i].isSuccess() )
                    System.out.println("record " + saveResults[i].getId() + " was updated successfully");
                else {                        
                    // There were errors during the update call, so loop through and print them out
                    System.out.println("record " + saveResults[i].getId() + " failed to save");
                    for ( int j = 0; j < saveResults[i].getErrors().length; j++ ) {
                        Error err = saveResults[i].getErrors()[j];
                        System.out.println("error code: " + err.getStatusCode().toString());
                        System.out.println("error message: " + err.getMessage());
                    }
                }
            }
        }
    } catch (ConnectionException ce) {
            ce.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an anchor link that I want to disable once the user clicks
I have a form. When the user clicks disable I want to disable all
When I disabled Numeric UpDown control I want that user can still read its
I have a UIButton that I disable for a few seconds after the user
I have a Composite that I want to be able to enable/disable programatically. The
i have some user control and i want to disable Alt + F4 oportunity
I want to disable a hyperlink so that if user clicks on the link,
I am using VB for coding. I want to disable postback when user presses
I have a field which I do not want to user to edit that.
I want to disable click on a certain <div> so that when you select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.