public class AccountContactC {
public string recid{get;set;}
public list<Account> Acclst{get;set;}
public List<ContactWrapper> contacts {get;set;}
public AccountContactC(){
contacts = new List<ContactWrapper>();
Acclst = [SELECT Id, Name FROM Account LIMIT 10];
}
public void setupContacts() {
for(Contact c : [SELECT id, FirstName, LastName, Email, createdBy.Name FROM Contact WHERE AccountId=:recId]){
contacts.add(new ContactWrapper (c.CreatedBy.name, c));
}
}
public class ContactWrapper{
public String userName {get; set;}
public Contact ct {get; set;}
public ContactWrapper(String userName, Contact ct) {
this.userName = userName;
this.ct = ct;
}
}
}
If you don't want UserName then you can use below code.
public class AccountContactC {
public string recid{get;set;}
public list<Account> Acclst{get;set;}
public List<Contact> contacts {get; set;}
public AccountContactC(){
Acclst = [SELECT Id, Name FROM Account LIMIT 10];
contacts=null;
}
public void setupContacts() {
contacts=[SELECT id, FirstName, LastName, Email FROM Contact WHERE AccountId=:recId];
}
}
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Please refer the below links
https://developer.salesforce.com/forums/?id=906F0000000AnpYIAS
https://developer.salesforce.com/forums/?id=906F0000000Aiy4IAC
https://developer.salesforce.com/forums/?id=906F0000000BS6XIAW
Thanks
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
If you don't want UserName then you can use below code.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas