• Thomas Gordon 20
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies
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;
    }
}
select id, name from account where name = :user.userrole.name

does not return anything due to an error in this query. the bind variable is used in a different query so it is valid as a value. This must be a relationship issue. Can anybody confirm or offer a fix please?
 
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;
    }
}
select id, name from account where name = :user.userrole.name

does not return anything due to an error in this query. the bind variable is used in a different query so it is valid as a value. This must be a relationship issue. Can anybody confirm or offer a fix please?