You need to sign in to do that
Don't have an account?
Invalid foreign key relationship
hello
Iam getting an invalid foreign key relationship error
for(Voucher__c queryvouchers : [select (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 ) Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,Name,CreatedDate from Voucher__c where id=: Voucherid ])
{
if((date.today().month() - queryvouchers.Treasure_Chest_Applications__r.Date_of_the_Event__c.month() == 1) && (date.today().year() == queryvouchers.Treasure_Chest_Applications__r.Date_of_the_Event__c.year())) {
RelatedVoucher.add(queryvouchers);
Is Treasure Chest Application a parent or child to Voucher? In other words, if you are looking at a voucher record, is there a field for Treasure Chest Application or is there a list of them?
Since you are using an inner SOQL query, this query is attempting to pull multiple Treasure Chest Applications for each Voucher, but your if statement is treating it like there is only one Treasure Chest Application for each Voucher. You need to treat queryvouchers.Treasure_Chest_Applications__r like a list.
If in fact Treasure Chest Application is a parent of Voucher, then you should construct your query differently:
[SELECT Treasure_Chest_Application__r.Date_of_the_Event__c, Total_Amount_Raised_for_Events__c, .... FROM Voucher__c WHERE Id = :Voucherid]
i want to get the multiple treasure chest records for the particular voucher.
Since Treasure_Chest_Applications__r is a list, you cannot get a property of queryvoucher.Treasure_Chest_Applications__r. Instead, you need to access each element of that list, like so: