You need to sign in to do that
Don't have an account?
Saravanan Sivalingam 1
Roll-up counts in look up related objects in Apex, its not working....what is the mistake, any suggestions..
Master__c(Parent Object)
child1__c (Child Object).
Child1_count__c(Roll up summary field/Custom Field).
c.MD1__c(Lookup field).
trigger RollupChild on child1__c (after insert,after delete, after undelete) {
List<id> master = new List<id>();
if(Trigger.isInsert || Trigger.isUndelete)
{
For(child1__c c : Trigger.new)
{
master.add(c.MD1__c);
}
}
if(Trigger.isDelete)
{
For(Child1__c c : Trigger.old)
{
master.add(c.MD1__c);
}
}
List<Master__c> mas = new List<Master__c>();
For(Master__c m : [SELECT Child1_count__c FROM Master__c WHERE id =: master])
{
m.Child1_count__c = m.Child1_count__c+1;
mas.add(m);
}
update mas;
}
child1__c (Child Object).
Child1_count__c(Roll up summary field/Custom Field).
c.MD1__c(Lookup field).
trigger RollupChild on child1__c (after insert,after delete, after undelete) {
List<id> master = new List<id>();
if(Trigger.isInsert || Trigger.isUndelete)
{
For(child1__c c : Trigger.new)
{
master.add(c.MD1__c);
}
}
if(Trigger.isDelete)
{
For(Child1__c c : Trigger.old)
{
master.add(c.MD1__c);
}
}
List<Master__c> mas = new List<Master__c>();
For(Master__c m : [SELECT Child1_count__c FROM Master__c WHERE id =: master])
{
m.Child1_count__c = m.Child1_count__c+1;
mas.add(m);
}
update mas;
}