I believe you are trying to associate a single contact to multiple accounts. This functionality was released in Spring 16′ and is implemented through a Salesforce Junction object – AccountContactRelation.
I assume you have already enabled this functionality through the UI and a parent Account is declared for this Contact.
I have modified your code to associate the contact to all 20 account.
global class UpdateProjectNameBatch implements Database.Batchable
<sObject>
{ ID conId = ‘0037F00000IfCCKQA3’; //Add the contact Id here
List<AccountContactRelation> ListInsertion = new List<AccountContactRelation>();
String query = ‘Select Id,Name FROM Account WHERE Name = ‘SampleAccountOne”;
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Account> batch){
for (Account a : batch)
{
AccountContactRelation c = new AccountContactRelation();
c.AccountId = a.id;
c.contactId = conId;
ListInsertion.add(c);
}
Insert ListInsertion;
}
global void finish(Database.BatchableContext bc)
{
//DoNothing.
}
}