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
Aryan JhaAryan Jha 

contact is not made in account

public class AccountWithContacts {
    public static void Accountwithcontactsassociated()
    {
        Set<Id>accId=new Set<Id>();
        List<Contact>contacts=new List<Contact>();
        List<Account>accList=[SELECT Id,Name,Phone,(SELECT firstname,Phone FROM Contacts) FROM Account WHERE Id=:accID];
        for(Account acc:accList)
        {
            for(Contact con:acc.contacts)
            {
                
            
           
            con.AccountId=acc.Id;
            con.FirstName=acc.Name;
            con.Phone=acc.phone;
            contacts.add(con);
            }
        }
        update contacts;
    }

}
AbhinavAbhinav (Salesforce Developers) 
Hi Aryan,

How you are calling this method?
accID which you are using in where clause doesn't seems to have any data?

Thanks!
Aryan JhaAryan Jha
So what we will do
AbhinavAbhinav (Salesforce Developers) 
Could you please tell your requirement so that I can suggest suitable references.
Aryan JhaAryan Jha
Sir i have to update contact records which is associated with account through query
AbhinavAbhinav (Salesforce Developers) 
You have to see how you have to update i.e via trigger approach, via Batch Class  or even you can do that by executing block of code from Anonymous window as per your requirement.

Attaching some closest references

Trigger
https://developer.salesforce.com/forums/?id=9060G000000IBeVQAW

Batch
https://www.sfdcamplified.com/2019/04/update-account-and-related-contacts-using-batch-and-scheduled-apex.html

Thanks!