You need to sign in to do that
Don't have an account?
sfdc-admin-sm
Invalid foreign key relationship when trying to add an Account to a map
Hello,
I am getting the following error: Invalid foreign key relationship: License__c.Account__c at line 21 column 23 for my code: mapAcct.put(ObjLic.Account__c.Id, ObjLic.Account__c); in the below trigger code snippet. What should the correct code be to add an Acciount Id and Account record to the mapAcct? The License__c custom object has a lookup relationship to Accounts.
My code:
Set<Id> licIds = new Set<Id>();
for(License__c l : Trigger.new){
if(l.Expiration_Date__c > Date.Today()){
licIds.add(l.Id);
}
}
System.debug('<<<licIds size = ' +licIds.size());
Map<Id, Account> mapAcct;
if(licIds != NULL){
for(License__c ObjLic : licIds){
mapAcct.put(ObjLic.Account__c.Id, ObjLic.Account__c);
}
}
I am getting the following error: Invalid foreign key relationship: License__c.Account__c at line 21 column 23 for my code: mapAcct.put(ObjLic.Account__c.Id, ObjLic.Account__c); in the below trigger code snippet. What should the correct code be to add an Acciount Id and Account record to the mapAcct? The License__c custom object has a lookup relationship to Accounts.
My code:
Set<Id> licIds = new Set<Id>();
for(License__c l : Trigger.new){
if(l.Expiration_Date__c > Date.Today()){
licIds.add(l.Id);
}
}
System.debug('<<<licIds size = ' +licIds.size());
Map<Id, Account> mapAcct;
if(licIds != NULL){
for(License__c ObjLic : licIds){
mapAcct.put(ObjLic.Account__c.Id, ObjLic.Account__c);
}
}
Set<Id> licIds = new Set<Id>();
for(License__c l : Trigger.new){
if(l.Expiration_Date__c > Date.Today()){
// licIds.add(l.Id);
licids.add(l.Account__c);
}
}
System.debug('<<<licIds size = ' +licIds.size());
Map<Id, Account> mapAcct;
if(licIds != NULL){
// for(License__c ObjLic : licIds){
// mapAcct.put(ObjLic.Account__c.Id, ObjLic.Account__c);
// }
for (Account acc : [SELECT Id FROM Account WHERE Id IN :licIds]) {
mapAcct.put(acc.Id, acc);
}
}