Monday 1 December 2014

child to parent Field update using Trigger

trigger childtoparentupdation on Contact (after insert, after update) {

public static Boolean bool = true;

if(bool){
 bool = false;

 List<Contact> listcont  =  new List<Contact>();
 List<Account> listacct  =  new List<Account>();
 List<Account> listacct1 =  new List<Account>();

 set<id> setid  = new set<id>();
 set<id> setid1 = new set<id>();

 for(Contact con : Trigger.New){
  setid.add(con.id);  
 }
 
 List<Contact> contact = [select id, Languages__c,Account.id from contact where id IN:setid];
 
 for(contact conn:trigger.new){
 setid1.add(conn.accountid);
 }
 listacct = [select Id, SLASerialNumber__c from Account where id in:setid1];

 for(Account acc: listacct ){
 if(acc.SLASerialNumber__c == null){
  acc.SLASerialNumber__c ='Testing';
  listacct1.add(acc);
  }
 update listacct1;
}
}

No comments:

Post a Comment