Skip to main content
deleted 23 characters in body
Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

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 ;
    }   
}

}

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);

            }
        }
    }
     update conlist ;
}   

}

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<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 ;
    }   
}
Source Link

Trigger on fire before update

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,

But if i am update this field its not working ,i am writing another on this topic,

This is the update code,

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);

            }
        }
    }
     update conlist ;
}   

}