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
samson sfdcsamson sfdc 

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); 
        } 
    } 
}
 
Best Answer chosen by samson sfdc
Himanshu ParasharHimanshu Parashar
Hi Samson,

record Id always required in update call so you need to first query the data like and then you can only update.
 
List<User> userlist= [select id from user where contactid=:Conid limit 1]

if(userlist.size()>0)
{
    User usr = new User(id=
 userlist[0].id,ContactId=cont.Id,Email=cont.Email,FirstName=cont.FirstName,LastName=cont.LastName,Phone=cont.Phone);
}


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

Himanshu ParasharHimanshu Parashar
Hi Samson,

record Id always required in update call so you need to first query the data like and then you can only update.
 
List<User> userlist= [select id from user where contactid=:Conid limit 1]

if(userlist.size()>0)
{
    User usr = new User(id=
 userlist[0].id,ContactId=cont.Id,Email=cont.Email,FirstName=cont.FirstName,LastName=cont.LastName,Phone=cont.Phone);
}


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.
 
This was selected as the best answer
Abhi_TripathiAbhi_Tripathi
Hi Samson,

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/



 
samson sfdcsamson sfdc
Thank you. Himanshu & Abhi.