You need to sign in to do that
Don't have an account?
vmarco
How do I retrieve a Profile ID using the Java WSC API?
I need to assign a profile to a user using the Java WSC API. Currently I use:
sobj.setField("ProfileId", parent.getProfileId);
However, I need to set the profile to a specific Profile. I assume this means looking up that profile (ie. "Standard User"). However, I cannot quite get this to work.
Any help?
Vince
Hi,
This is a simple method to get any profile's id and assign it to any user or bulk users as per your need.
package myPackage;
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.soap.enterprise.sobject.User;
import com.sforce.soap.enterprise.sobject.Profile;
import com.sforce.ws.ConnectorConfig;
public class GetProfleID
{
static final String USERNAME = "yourusername";
static final String PASSWORD = "yourpassword+sectoken";
static EnterpriseConnection connection;
public static void main(String[] args)
{
ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
try
{
connection = Connector.newConnection(config);
QueryResult queryResultsUser = connection.query("SELECT Id, Name, ProfileID FROM User where CommunityNickname = 'samish_chatter' Limit 1");
QueryResult queryResultsProf = connection.query("SELECT Id, Name FROM Profile where name = 'Authenticated Website' LIMIT 1");
SObject[] objListUser = queryResultsUser.getRecords();
SObject[] objListProf = queryResultsProf.getRecords();
User u = (User)objListUser[0];
Profile p = (Profile)objListProf[0];
u.setProfileId(p.getId());
System.out.println("User new profile id = "+u.getProfileId());
connection.update(objListUser);
}
catch(Exception ex)
{
System.out.println("@@@"+ ex.getMessage());
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.