Error creating user SalesForce LICENSE_LIMIT_EXCEEDED: License limit exceeded

I want to create 5-6 SalesForce users programmatically using the SOAP API. I use the Partner API and I have a sandbox for developers. I am extracting user information from a database table and then using the API, I want to create these 5-6 users at a time. I can create one user, however, after creating another user, he throws the LICENSE_LIMIT_EXCEEDED:License Limit Exceeded error.

This is a snapshot of my code that retrieves user information from a database and then creates the user programmatically:

 SObject user = new SObject(); user.setType("User"); while (rs.next()) { user.setField("Alias", rs.getString("Alias")); user.setField("Email", rs.getString("Email")); user.setField("EmailEncodingKey", rs.getString("EmailEncodingKey")); user.setField("LanguageLocaleKey", "En_US"); user.setField("LastName", rs.getString("LastName")); user.setField("LocaleSidKey", rs.getString("LocaleSidKey")); user.setField("TimeZoneSidKey", "America/Los_Angeles"); user.setField("Username", rs.getString("Username")); user.setField("UserPermissionsCallCenterAutoLogin", "false"); user.setField("UserPermissionsMarketingUser", "false"); user.setField("UserPermissionsOfflineUser", "false"); user.setField("ProfileId", connection.getUserInfo().getProfileId()); SaveResult[] results = connection.create(new SObject[] { user }); System.out.println("Created user: " + results[0].getId()); if (results[0].isSuccess()) out.println("Created user: " + results[0].getId()); else out.println("Error: " + results[0].getErrors()[0].getStatusCode() + ":" + results[0].getErrors()[0].getMessage()); } QueryResult queryResults = connection .query("SELECT Id, Name from User " + "ORDER BY CreatedDate DESC LIMIT 5"); if (queryResults.getSize() > 0) { for (SObject s : queryResults.getRecords()) { out.println("Id: " + s.getField("Id") + " - Name: " + s.getField("Name")); } } 

Here I can create one user, however, after creating one user, he gives the error LICENSE_LIMIT_EXCEEDED:License Limit Exceeded .

This is the number of licenses available: enter image description here

I see that the licenses remaining for SalesForce are 0. However, I just want to create some users who do not have to be SalesForce users. This can be any type of user who just needs to log into my organization. When I try to create several different users, such as "Chatter Free", which has 5000 licenses using user.setField("UserType", "CsnOnly") , it gives the error INVALID_FIELD_FOR_INSERT_UPDATE:Unable to create/update fields: UserType

These are the users in my SalesForce: enter image description here

How to solve this problem? I just want to create some users from the database, which can then log into SalesForce. They are not required to be administrators. They may have minimal privileges, but they must be able to log into SalesForce.

+4
source share
2 answers

In the org developer, you cannot have more than two active users with Salesforce licenses. To create a user with a Chatter Free license, you only need to assign them a Chatter Free User profile - it will automatically install its license correctly based on the profile assigned to it (the UserType field UserType not edited).

Edit: in order to get the Chatter Free user profile ID without hard coding (since this can change from org to org), you will have to request it. I changed your code to include this request and also redesigned it to make only one PartnerConnection.create (just a suggestion, as it will save overhead on SOAP callouts):

 QueryResult profileQuery = connection.query("select Id from Profile where Name = 'Chatter Free User' limit 1"); SObject chatterFreeProfile; if ( profileQuery.getSize() > 0 ) { chatterFreeProfile = profileQuery.getRecords()[0]; } ArrayList<SObject> users = new ArrayList<SObject>(); while (rs.next()) { SObject user = new SObject(); user.setType("User"); user.setField("Alias", rs.getString("Alias")); user.setField("Email", rs.getString("Email")); user.setField("EmailEncodingKey", rs.getString("EmailEncodingKey")); user.setField("LanguageLocaleKey", "En_US"); user.setField("LastName", rs.getString("LastName")); user.setField("LocaleSidKey", rs.getString("LocaleSidKey")); user.setField("TimeZoneSidKey", "America/Los_Angeles"); user.setField("Username", rs.getString("Username")); user.setField("UserPermissionsCallCenterAutoLogin", "false"); user.setField("UserPermissionsMarketingUser", "false"); user.setField("UserPermissionsOfflineUser", "false"); if ( chatterFreeProfile != null ) user.setField("ProfileId", chatterFreeProfile.getField("Id")); else user.setField("ProfileId", connection.getUserInfo().getProfileId()); users.add(user); } if ( users.size() > 0 ) { SaveResult[] results = connection.create(users.toArray(new SObject[users.size()])); for ( int i = 0; i < saveResults.length; i++ ) { if (results[i].isSuccess()) out.println("Created user: " + results[i].getId()); else out.println("Error: " + results[i].getErrors()[0].getStatusCode() + ":" + results[i].getErrors()[0].getMessage()); } } QueryResult queryResults = connection.query("SELECT Id, Name from User ORDER BY CreatedDate DESC LIMIT 5"); if ( queryResults.getSize() > 0 ) { for ( SObject s : queryResults.getRecords() ) { out.println("Id: " + s.getField("Id") + " - Name: " + s.getField("Name")); } } 
+4
source

You need to install ProfileId in the profile associated with the available license type, in your case with the profile on the Chatter Free platform, Salesforce Platform, or one of your other available license types. Each profile is associated with a specific UserLicense entry, for example:

  • "SFDC": Full Salesforce License
  • 'CSN_User': free license
  • "AUL": Salesforce platform license.

(To find out more, run the query in the UserLicense object).

So, you need to request Profile entries for the available license types, and then associate them with your new users, for example

 QueryResult profileQuery = connection.query( "SELECT Id FROM Profile " + "WHERE UserLicense.Name = 'Chatter Free' LIMIT 1" ); SObject chatterFreeProfile; if ( profileQuery.getSize() > 0 ) { chatterFreeProfile = profileQuery.getRecords()[0]; user.setField("ProfileId", chatterFreeProfile.getField("Id")); } 
+2
source

Source: https://habr.com/ru/post/1436371/


All Articles