У меня есть RESTful API, который позволяет мне что-то обновлять, код, подобный следующему:
Поскольку это внешний пользователь (пользователь автоматически создается с личной учетной записью).Я хочу знать, почему я не могу обновить имя пользователя?Если я обновлю это, произойдет ошибка:
10: 38: 10: 978 USER_DEBUG [283] | DEBUG | === Ошибка обновления пользователя === Ошибка обновления.Первое исключение в строке 0 с идентификатором 0030m00000IztRaAAJ;первая ошибка: MIXED_DML_OPERATION, операция DML над объектом установки не разрешена после обновления неустановочного объекта (или наоборот): учетная запись, исходный объект: пользователь: []
Вот вамкоды:
public static CA_RSEUserResponse updateUserInfo(CA_RSEUserInfo rseUserInfo) {
User u = null;
CA_RSEUserResponse resp = new CA_RSEUserResponse();
Savepoint sv = Database.setSavepoint();
try {
// 1. Update User
u = [
SELECT Username,Email,FirstName,LastName,Id,ContactId
FROM User
WHERE Id = :rseUserInfo.id
LIMIT 1
];
System.debug('=== User ID is ===' + rseUserInfo.id);
System.debug('User Contact ID is ===' + u.ContactId);
u.Username = rseUserInfo.email_address;
u.Email = rseUserInfo.email_address;
u.FirstName = rseUserInfo.first_name;
u.LastName = rseUserInfo.last_name;
update u;
// 2. Find the related contact and fill in the info
Contact foundContact = [
SELECT LastName,FirstName,Birthdate,MailingCity,MailingState,
MailingPostalCode,Phone,CA_Subscription_Status__c,CA_Gender__c,
CA_Dependants__c,CA_SkillLevel__c,CA_FavoriteCuisines__c,
CA_RecipeDislikes__c,CA_RecipeLikes__c,CA_Retailer__c,
CA_LanguagePreference__c,CA_EnjoymentLevel__c,CA_RepeatFrequency__c,
CA_AdventureLevel__c,CA_CreatedProfile__c,CA_CompletedProfile__c,
CA_HouseholdAdults__c
FROM Contact
WHERE Id = :u.ContactId
LIMIT 1
];
System.debug('Birth Year ==='+rseUserInfo.birth_year);
foundContact.LastName = rseUserInfo.last_name;
foundContact.FirstName = rseUserInfo.first_name;
foundContact.Birthdate = rseUserInfo.birth_year;
foundContact.MailingCity = rseUserInfo.city;
foundContact.MailingState = rseUserInfo.state;
foundContact.MailingPostalCode = rseUserInfo.zip;
foundContact.Phone = rseUserInfo.mobile_phone;
foundContact.CA_Subscription_Status__c = rseUserInfo.subscription_status;
foundContact.CA_Gender__c = rseUserInfo.gender;
foundContact.CA_Dependants__c = rseUserInfo.dependants;
foundContact.CA_SkillLevel__c = rseUserInfo.skill_level;
foundContact.CA_FavoriteCuisines__c = rseUserInfo.favorite_cuisines;
foundContact.CA_RecipeDislikes__c = rseUserInfo.recipe_dislikes;
foundContact.CA_RecipeLikes__c = rseUserInfo.recipe_favorites;
foundContact.CA_Retailer__c = rseUserInfo.retailer;
foundContact.CA_LanguagePreference__c = rseUserInfo.language_preference;
foundContact.CA_EnjoymentLevel__c = rseUserInfo.enjoyment_level;
foundContact.CA_RepeatFrequency__c = rseUserInfo.repeat_frequency;
foundContact.CA_AdventureLevel__c = rseUserInfo.adventure_level;
foundContact.CA_CreatedProfile__c = rseUserInfo.created_profile;
foundContact.CA_CompletedProfile__c = rseUserInfo.completed_profile;
foundContact.CA_HouseholdAdults__c = rseUserInfo.household_adults;
update foundContact;
resp.errorMsg = null;
resp.content = rseUserInfo;
} catch (Exception ex) {
Database.rollback(sv);
System.debug('=== User Updated Error ===' + ex.getMessage());
rseUserInfo = null;
}
return resp;
Если я не обновлю имя пользователя User.user, все будет хорошо ... Так почему и как обновить это поле?