You need to sign in to do that
Don't have an account?
ch ranjith
I have junction object which relates to account and contact. Whenever new record is inserted in junction object the account billing street need to be copied in contact mailing street . I tried this but its not working
trigger copystreetaddress on Join_object__c(after insert)
{
list<contact> conlist=new list<contact>();
if(trigger.isUpdate)
{
Set<Id> accountId = new Set<Id>();
Set<Id> contactId = new Set<Id>();
for(Join_object__c tempJ : Trigger.new)
{
accountId.add(tempJ.Account__c);
contactId.add(tempJ.Contact__c);
}
List<Account> AccountList = [Select id,Name,BillingStreet from Account where id in: accountId];
List<Contact> ContactList = [Select id,Name,mailingStreet from Contact where id in: contactId];
for(Join_object__c tempJ : Trigger.new)
{
for(Account tempAcc : AccountList)
{
if(tempJ.Account__c == tempAcc.Id)
{
for(Contact tempCon : ContactList)
{
if(tempJ.Contact__c == tempCon.Id)
{
tempCon.mailingstreet = tempAcc.BillingStreet;
conlist.add(tempcon);
}
}
}
}
}
}
update ConList;
}
{
list<contact> conlist=new list<contact>();
if(trigger.isUpdate)
{
Set<Id> accountId = new Set<Id>();
Set<Id> contactId = new Set<Id>();
for(Join_object__c tempJ : Trigger.new)
{
accountId.add(tempJ.Account__c);
contactId.add(tempJ.Contact__c);
}
List<Account> AccountList = [Select id,Name,BillingStreet from Account where id in: accountId];
List<Contact> ContactList = [Select id,Name,mailingStreet from Contact where id in: contactId];
for(Join_object__c tempJ : Trigger.new)
{
for(Account tempAcc : AccountList)
{
if(tempJ.Account__c == tempAcc.Id)
{
for(Contact tempCon : ContactList)
{
if(tempJ.Contact__c == tempCon.Id)
{
tempCon.mailingstreet = tempAcc.BillingStreet;
conlist.add(tempcon);
}
}
}
}
}
}
update ConList;
}
Your trigger is fire on after insert, but in trigger you applied trigger.isupdate condtion.
trigger copystreetaddress on Join_object__c(after insert)
{
list<contact> conlist=new list<contact>();
if(trigger.isUpdate) change it to isInsert
Thanks