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
aravind swaminathanaravind swaminathan 

Regarding Updating Salesforce Contact Information

Hello,
We are trying to update the user profile data(ie Contacts information).When i am trying to do 
SaveResult[] rsults=binding.update(userList);
I am getting an error -Invalid format of Id.I am sending Id as employee number.Can you please let me know if Id is salesforce identifier?If yes,How can i get that Id?And also please advise me if i am using the right api method to update Contact Information?

Thanks.


 
Daniel BallingerDaniel Ballinger

The sObject Id field should be the 15 or 18 character Salesforce Base64 Id. See What are Salesforce ID's composed of? (http://salesforce.stackexchange.com/q/1653/102)

If you want to use an employee Id you should create a custom field on Contact to store this Id. Mark it an a unique external Id. See What is an external ID? (https://help.salesforce.com/apex/HTViewHelpDoc?id=faq_import_general_what_is_an_external.htm&language=en)

Then you can swtich to an upsert rather than an update. The upsert call will using the External Id to find the correct record to update. See Upsert() (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_upsert.htm)

aravind swaminathanaravind swaminathan
Thanks a lot for your reply. I have 1 more question.When i try to do upsert with all the information including profileId, i get "Cannot grant or remove a profile with modify all data,<br>without having the modify all data permission yourself.: Profile ID" error.Without Profile Id, am able to update properly.
For Manager/ManagerId field, what is the encoding thats used. i tried decoding using base64 and it didnt work.
Daniel BallingerDaniel Ballinger
The message is telling you that you are trying to assign a Profile that would grant a user the "Modify All Data" permission while the API user you currently connect with doesn't have a profile that grants that permission. Essentially the Profile you are trying to assign has a greater level of access than you do. You can't modify it as you could use it to boost your or another users level of access to the system beyond what you currently have.

I'd expect the ManagerId field to be a standard 15/18 character Salesforce ID field with a User Id.
aravind swaminathanaravind swaminathan
Thanks.1 more question-
I am trying to use upsert to update a record and i get this message-"Duplicate Username.<br>The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). ".
It works for certain users but not all?The empoyee number, email address match but i get this exception.

Another thing is when i try to insert new user, i get an error asking to "Business unit must be defined by user".I am already passing company name,division,district etc.

Can you please help me in this regard.

Thanks.
Daniel BallingerDaniel Ballinger
The Duplicate Username error message is exactly what is says. That Username has already been used with Salesforce. NOTE: this isn't just checked against your current org. It is checked against every single Salesforce org. Usernames are unique across all of Salesforce.

I'm not sure on the business unit requirement. I'd suggest raising a new question to investigate that explicity. 
aravind swaminathanaravind swaminathan
But i am trying to update the profile information.So, even if username exists, it should have updated the record right when i use Upsert.Why is it trying to insert and giving me "Duplicate Username.<br>The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). ".Is it looking at UserName field only or is it looking at any other fields to determine whether it is a insert or update?Is it not supposed to insert when username does not exist and update when username exists?
Daniel BallingerDaniel Ballinger

If you are doing an Upsert without specifying the Id field for the entity in question you need to set the externalIdFieldName parameter.

From the docs (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_upsert.htm):

ExternalIDFieldName

Contains the name of the field on this object with the external ID field attribute for custom objects or the idLookup field property for standard objects. The idLookup field property is usually on a field that is the object's ID field or name field, but there are exceptions, so check for the presence of the property in the object you wish to upsert().

So make sure you are setting externalIdFieldName to "Username". It should be possible to use this field, as it has the idLookup (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm#username) property.

aravind swaminathanaravind swaminathan
Thanks for your reply.We are using Custom attribute "EmployeeNumber__c" and passing employee number to it like below.It updates for certain records and for some , we get "Duplicate Username.<br>The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). ".Can you help me understand whats going wrong here.I see those records in salesforce UI portal too.

userFields[1] = makeElement("Alias", u.firstName.Substring(0, 1) + lastName);
userFields[2] = makeElement("CompanyName", u.companyName);
userFields[3] = makeElement("Department", u.department);
userFields[4] = makeElement("Division", u.division);
userFields[5] = makeElement("Email", u.email);
userFields[6] = makeElement("EmailEncodingKey", u.emailEncodingKey);
userFields[7] = makeElement("EmployeeNumber", u.employeeNumber);
userFields[8] = makeElement("Fax", u.fax);
userFields[9] = makeElement("FederationIdentifier", u.federationIdentifier);
userFields[10] = makeElement("FirstName", u.firstName);
userFields[11] = makeElement("LanguageLocaleKey", u.languageLocaleKey);
userFields[12] = makeElement("LastName", u.lastName);
userFields[13] = makeElement("LocaleSidKey", u.localeSidKey);
userFields[14] = makeElement("MobilePhone", u.mobilePhone);
userFields[15] = makeElement("CommunityNickname", u.firstName.Substring(0, 1) + "_" + u.lastName);
userFields[16] = makeElement("Phone", u.phone);
userFields[17] = makeElement("TimeZoneSidKey", "America/Chicago");
userFields[18] = makeElement("Username", u.email);
userFields[19] = makeElement("EmployeeNumber__c", u.employeeNumber);
userFields[20] = makeElement("Title", u.title);
userFields[21] = makeElement("ProfileId", "xyz");
userFields[22] = makeElement("ManagerId", u.manager);
newUser.type = "User";
newUser.Any = userFields;
userList[x] = newUser;
UpsertResult[] results = binding.upsert("EmployeeNumber__c", userList);
for (int j = 0; j < results.Length; j++)
{
if (j == x)
{
if (results[j].success)
{
successes++;
else
{
errors++;
for (int i = 0; i < results[j].errors.Length; i++)
{
Error err = results[j].errors[i];
Console.WriteLine("Errors were found on item " + j.ToString());
Console.WriteLine("Error code is: " + err.statusCode.ToString());
Console.WriteLine("Error message: " + err.message);
}
}
}
}