You need to sign in to do that
Don't have an account?
Thomas Gordon 20
need a loop
I know I need a loop in here somewhere to loop through this list, but I can't get it right. I get" initial term of field expression must be a concrete SObject : list. Can somebody save me please? I'm looking to create a contact from anew user. I know the trigger wont work.
public class createContactFromUser {
public static void ContactCreate(){
List<Contact> ct = new List<Contact>();
List<User> usr = new List<User>();
usr=[select id, Name, AccountId, Firstname, Lastname, Email from User
where profileId ='00et0000000HfNg'
and isActive = true];
System.debug(usr.size());
if(usr != null && usr.size() > 0) {
Contact uc = new Contact();
uc.Name = usr.Name;
uc.Email = usr.Email;
uc.AccountId = usr.AccountId;
ct.add(uc);
}
insert ct;
}
}
public class createContactFromUser {
public static void ContactCreate(){
List<Contact> ct = new List<Contact>();
List<User> usr = new List<User>();
usr=[select id, Name, AccountId, Firstname, Lastname, Email from User
where profileId ='00et0000000HfNg'
and isActive = true];
System.debug(usr.size());
if(usr != null && usr.size() > 0) {
Contact uc = new Contact();
uc.Name = usr.Name;
uc.Email = usr.Email;
uc.AccountId = usr.AccountId;
ct.add(uc);
}
insert ct;
}
}
Use for loop here
if(usr != null && usr.size() > 0) {
for(user u: usr)
{
Contact uc = new Contact();
uc.Name = u.Name;
uc.Email = u.Email;
uc.AccountId = u.AccountId;
ct.add(uc);
}
}
Insert ct;
Thanks
All Answers
Use for loop here
if(usr != null && usr.size() > 0) {
for(user u: usr)
{
Contact uc = new Contact();
uc.Name = u.Name;
uc.Email = u.Email;
uc.AccountId = u.AccountId;
ct.add(uc);
}
}
Insert ct;
Thanks
Contact uc = new Contact();
uc.FirstName = u.FirstName;
uc.LastName = u.LastName;
uc.Email = u.Email;
uc.AccountId = u.AccountId;
Try this let me know if this is fixed.
Thanks
Have you called this class in Trigger (user Object)?
Thanks