I created a custom field on Account Create_contact__c
which should be checked if any contact is inserted related to that account. I did write the following trigger to achieve this but ended up with writing SOQL queries and DML inside loop. Can someone suggest proper way to put these outside loop.
trigger trg3 on Contact (after insert) {
if(trigger.isinsert){
list<contact> con = trigger.new;
for(contact c : con){
list<Account> acc = [SELECT id from Account WHERE id =: c.AccountId];
for(Account a : acc){
a.Create_Contact__c = true;
update a;
}
}
}
}
Thanks