everyone Guys can help me.
I am creating a one custom field called contact name, in account object. If i am insert any value in this custom field automatically same value insert in contact object I am done this,
public class accountwithhandlerclass
{
public static void handlerMethod(List acc)
{
List conlist = New list();
id accid ;
string accname ;
for(Account ac : acc)
{
accid = ac.id ;
accname = ac.contact_name__c ;
system.debug('accid....'+accid);
system.debug('accname....'+accname);
}
List acclist = New list();
acclist = [select name,id,contact_name__c,(select name,id from contacts) from account where id = :accid];
system.debug('acclist....'+acclist);
for(Account a : acclist)
{
for(contact con : a.contacts)
{
if(accname != con.name)
{
System.debug('accname....'+accname);
Contact c = New Contact();
c.Lastname = accname ;
c.accountid = accid ;
Conlist.add(c);
system.debug('conlist....'+conlist);
public class accountwithhandlerclass
{
public static void handlerMethod(List<Account> acc)
{
List<contact> conlist = New list<contact>();
id accid ;
string accname ;
for(Account ac : acc)
{
accid = ac.id ;
accname = ac.contact_name__c ;
system.debug('accid....'+accid);
system.debug('accname....'+accname);
}
List<Account> acclist = New list<Account>();
acclist = [select name,id,contact_name__c,(select name,id from contacts) from account where id = :accid];
system.debug('acclist....'+acclist);
for(Account a : acclist)
{
for(contact con : a.contacts)
{
if(accname != con.name)
{
System.debug('accname....'+accname);
Contact c = New Contact();
c.Lastname = accname ;
c.accountid = accid ;
Conlist.add(c);
system.debug('conlist....'+conlist);
}
}
}
update conlist ;
}
}
}