function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kandy11kandy11 

Values of fields are getting doubled from different recvords of same object....

public List<Voucher__c> getRelatedVoucher() {

NumberEventsBenefiting = 0;
TotalRaffles = 0;
TotalEvents = 0;
RelatedVoucher = new List<Voucher__c>();
RelatedTreasureChestApplications = new List<Treasure_Chest_Application__c>();
// this.Voucherid = 'a1Ac0000000VaCi';
if(Voucherid != null && Voucherid!= ''){


for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){

if((date.today().month() - TCA.Date_of_the_Event__c.month() == 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}

 

 


for(Voucher__c CalVouchers : RelatedVoucher ){
for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if((date.today().month() - TCA1.Date_of_the_Event__c.month() == 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){



NumberEventsBenefiting = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);

}
}
}
}
return RelatedVoucher;
}