You need to sign in to do that
Don't have an account?
Sindhu Ambarkar
When new record is created in account object before new record is inserted into account,delete all the contact records with this account name it is working as expected
Hi,
trigger contactrecords on Account (before insert)
{
List<String> myname=new List<String>();
for(Account a:trigger.new)
{
myname.add(a.name);
}
List<contact> mycontact=[select id,name from contact where name in:myname];
delete mycontact;
}
Please help me.
trigger contactrecords on Account (before insert)
{
List<String> myname=new List<String>();
for(Account a:trigger.new)
{
myname.add(a.name);
}
List<contact> mycontact=[select id,name from contact where name in:myname];
delete mycontact;
}
Please help me.
Thanks!
can you tell me a correct answer of this
below is the working code for the above trigger,
hope you problem will resolved now.....
trigger:-
I went through your code, the trigger work if your requirement is something like deleting the existing record of Contact where the contact name is as same as the newly created account name then it will delete the record in the contact.
You may also add event 'after update' on the trigger if any account name is updated with a similar name in the contact record.
suppose same account was there one account was contact but when we create a account on same name the prebious conatct name was not delete it was ther on the same account
if(trigger.isInsert) {
List<string> aNames= new list<string>();
For(Account ac: Trigger.new){
aNames.add(ac.name);
}
List<Contact> clist= [select name,id from contact where name in :lname];
if(clist.size()>0){
delete clist;
}
}