You need to sign in to do that
Don't have an account?

MISSING_ARGUMENT, Id not specified in an update call
I'm trying to update the User object (Commmunity Portal user) whenever the details like First Name, last name, email & phone are update in Contact object.
Apex Class
----------------
global class UpdateUserfromContact{
public static void updateUsers(String ConId) {
Contact cont = [select Id,Email,FirstName,LastName,Phone
from Contact
where Id=:ConId];
if (cont!=null && cont.Id!=null) {
User usr = new User(ContactId=cont.Id,Email=cont.Email,FirstName=cont.FirstName,LastName=cont.LastName,Phone=cont.Phone);
update usr;
}
}
}
Trigger on Update Contact
-------------------------------------
trigger cc_hug_UpdateUserfromContact on Contact (after update) {
if (Trigger.new.size()==1)
{
Contact u = Trigger.new[0];
if (u.Id!=null) {
cc_hug_UpdateUserfromContact.updateUsers(u.Id);
}
}
}
Apex Class
----------------
global class UpdateUserfromContact{
public static void updateUsers(String ConId) {
Contact cont = [select Id,Email,FirstName,LastName,Phone
from Contact
where Id=:ConId];
if (cont!=null && cont.Id!=null) {
User usr = new User(ContactId=cont.Id,Email=cont.Email,FirstName=cont.FirstName,LastName=cont.LastName,Phone=cont.Phone);
update usr;
}
}
}
Trigger on Update Contact
-------------------------------------
trigger cc_hug_UpdateUserfromContact on Contact (after update) {
if (Trigger.new.size()==1)
{
Contact u = Trigger.new[0];
if (u.Id!=null) {
cc_hug_UpdateUserfromContact.updateUsers(u.Id);
}
}
}
record Id always required in update call so you need to first query the data like and then you can only update.
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
All Answers
record Id always required in update call so you need to first query the data like and then you can only update.
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Its as simple as that you are not specifying Id for the User record and you are trying to Update it.
For an update it required to have an Id.
Controller is not getting Id for the record of the user while updating so its showing that error.
For more detailed view on trigger go for this post
http://abhithetechknight.blogspot.in/2014/06/basics-of-apex-trigger-for-beginners.html
Regards,
Abhi Tripathi
Salesforce Developer
Blog : http://abhithetechknight.blogspot.in/