Hi Mohit,
Yes, We can connect two object which has some sort of relationship between them like in account and contact.
Here is a sample code, which is on account object. In this trigger when an account is inserted or updated, then its related contact has same phone number in its record.
trigger CopyAccPhoneToConPhone on Account (after insert, after update)
{
list<contact> conlist = new list<contact>();
for (contact a : [select id, phone, Contact.AccountId, account.phone from contact where Contact.AccountId IN: trigger.new] )
{
if(a.accountid != null)
{
a.phone = a.account.phone;
conlist.add(a);
}
}
update conlist;
}
Hope this helps you.
Thanks