• Kiran Kumar 225
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
hi, I have a following code, which updates all child records when status changes from complete to not complete. but my code is not woking.
trigger status on Product__c (after update) {
    set<String> productId = new set<String>();
    for(Product__c pro : trigger.old){
        if(pro.Status__c == 'Complete'){
            productId.add(pro.id);
            System.debug('Completed--->'+pro);
        }    
    }
    List<Vehicle__c> vechicalList = new List<Vehicle__c>();
    for(Vehicle__c vech:[select id,name,Status__c,Product__r.Status__c from Vehicle__c WHERE Product__c IN: productId ]){
        system.debug('vech---->'+vech);
        if(vech.Product__r.Status__c== 'Not Completed'){
            vech.Status__c = 'Incomplete';
            vechicalList.add(vech);
       }
    }
    update vechicalList;
}
Kindlyletme know where I did mistake.
Hi, I have the following code it is throwing 

trigger ContactCount on Contact (after insert, after delete, after undelete,after update) {
    set<string> AccountIds = new set<string>();
    if(trigger.isinsert || trigger.Isundelete){
        for(Contact Con: trigger.new){
            AccountIds.add(con.AccountId);
            system.debug('AccountID-->'+con.AccountId);
        }
    }
    if(trigger.isDelete || trigger.isupdate){
        system.debug('Delete');
        for(Contact oldCon : trigger.old){
            AccountIds.add(oldCon.AccountId);  
            system.debug('Delete---2');
        }
    }
    List<Account> accountList = [select id,count__c,(select id from contacts) from Account Where ID IN:AccountIds];
    list<account> accountupdate = new List<Account>();
    for(Account acc : accountList){
        system.debug('Contacts--->'+acc.contacts.size());
        acc.count__c = acc.contacts.size();
        //accountupdate.add(acc);
    }
    update accountList;

}

It is throwing unexpected exception error. Please let me konw where i did the mistake 
Hi,
I have two objects A and B, A is the parent to B, both objacts have status fields, when ever Aobject Status is changed from "Inprogress" to "Complete"then all child B object status changed to "Complete".
Please send me the sample trigger.
hi, I have a following code, which updates all child records when status changes from complete to not complete. but my code is not woking.
trigger status on Product__c (after update) {
    set<String> productId = new set<String>();
    for(Product__c pro : trigger.old){
        if(pro.Status__c == 'Complete'){
            productId.add(pro.id);
            System.debug('Completed--->'+pro);
        }    
    }
    List<Vehicle__c> vechicalList = new List<Vehicle__c>();
    for(Vehicle__c vech:[select id,name,Status__c,Product__r.Status__c from Vehicle__c WHERE Product__c IN: productId ]){
        system.debug('vech---->'+vech);
        if(vech.Product__r.Status__c== 'Not Completed'){
            vech.Status__c = 'Incomplete';
            vechicalList.add(vech);
       }
    }
    update vechicalList;
}
Kindlyletme know where I did mistake.