You need to sign in to do that
Don't have an account?
Deepak Singh 116
Need a trigger which Update minimum date parent record from number of child record .
Hi,
I have to two custom object Building__c and lease__c bothe objects have a firld name Expiry date.Building__c is parent and lease__c is child in look relatioship.I can not create MD relatioship between them because of some reason.now i want a trigger which pick the minimum expiry date from the lease records and upadte by building__c expiry date.
Thanks in advence!
I have to two custom object Building__c and lease__c bothe objects have a firld name Expiry date.Building__c is parent and lease__c is child in look relatioship.I can not create MD relatioship between them because of some reason.now i want a trigger which pick the minimum expiry date from the lease records and upadte by building__c expiry date.
Thanks in advence!
All Answers
Please refer the below code.
Trigger:-
--------------
trigger ExpiryDateChangeTrg on lease__c (after insert, after update) {
ExpiryDateChangehelper.test(trigger.new);
}
Helper Class:-
--------------
public class ExpiryDateChangehelper
{
public static void test(List<lease__c> leaselist)
{
set<ID> setid=new set<ID>();
for(lease__c l : leaselist)
{
setid.add(l.Building__c);
}
List<Building__c> blist=[SELECT expiry_date__c from Building__c where Id IN:setid];
List<lease__c> lelist=[SELECT expiry_date__c from lease__c where Building__c IN:setid ];
List<lease__c> lelist2 = new List<lease__c>();
for(Building__c Build : blist)
{
for(lease__c le : lelist)
{
if(Build.expiry_date__c > le.expiry_date__c)
{
le.expiry_date__c=Build.expiry_date__c;
lelist2.add(le);
}
}
}
update lelist2;
}
}
Mark it as a best if it help you.
Thanks,
Ajay Dubedi
Steven Nsubuga.
I have a question Please expalian the followinhgg statment why we convert it to string.
buildingMap.get(String.valueOf(ar.get('Building__c'))).Expiry_date__c =Date.valueOf(ar.get('expr0'));