Friday, 9 October 2015

update the field values from child - to - Parent Trigger

parent --> quote
child --->quote_product__c

when ever quote _Product__c  object update values related quote object fileds also get updated

trigger UpdateFieldsfromQuote on Quote_Product__c (after update)
{
 Map<id,Quote_Product__c> Mapquoteprod =new Map<Id,Quote_Product__c>();
 for(Quote_Product__c qtp :trigger.new)
 {
    Mapquoteprod.put(qtp.Quote__c,qtp);
 }
    List<Quote> qtList = new List<Quote>();

 for(Quote qt  : [Select id,Brightness__c ,Color_styles__c,Ash__c,Bulk_cc__c
                                                                            from Quote where id =:Mapquoteprod.keyset()])
 {
   qt.Brightness__c    = Mapquoteprod.get(qt.id).Brightness__c;
   qt.Color_styles__c  = Mapquoteprod.get(qt.id).of_Colors_Styles__c;
   qt.Ash__c           = Mapquoteprod.get(qt.id).Ash__c;
   qt.Bulk_cc__c       = Mapquoteprod.get(qt.id).Bulk_CC_gm__c;
   qtList.add(qt);
 }
   if(!qtList.isempty())
   {
     update qtList;
   }
}

No comments:

Post a Comment