You need to sign in to do that
Don't have an account?
Ken sfdc1
Rollup Summary for lookup of custom objects
trigger CountSpeakerEvaluationsnew on Speaker_Evaluation_AEGR__c(after insert, after delete, after undelete) {
List<id> accIdList = new List<id>();
if(Trigger.isInsert || Trigger.isUndelete){
For(Speaker_Evaluation_AEGR__c con1 : Trigger.new){
accIdList.add(con1.Medical_Event_vod__c.id);
}
}
if(Trigger.isDelete){
For(Speaker_Evaluation_AEGR__c con1 : Trigger.old){
accIdList.add(con1.Medical_Event_vod__c.id);
}
}
List<Account> accUpdateList = new List<Account>();
For(Medical_Event_vod__c acc : [SELECT No_of_Speaker_Evaluations__c,(SELECT id FROM Speaker_Evaluations__r) FROM Medical_Event_vod__c WHERE id =: accIdList]){
acc.No_of_Speaker_Evaluations__c = acc.Speaker_Evaluations__c.size();
accUpdateList.add(acc);
}
try{
update accUpdateList;
}Catch(Exception e){
System.debug('Exception :'+e.getMessage());
}
}
Error: Compile Error: Invalid foreign key relationship: Speaker_Evaluation_AEGR__c.Medical_Event_vod__c at line 6 column 27
List<id> accIdList = new List<id>();
if(Trigger.isInsert || Trigger.isUndelete){
For(Speaker_Evaluation_AEGR__c con1 : Trigger.new){
accIdList.add(con1.Medical_Event_vod__c.id);
}
}
if(Trigger.isDelete){
For(Speaker_Evaluation_AEGR__c con1 : Trigger.old){
accIdList.add(con1.Medical_Event_vod__c.id);
}
}
List<Account> accUpdateList = new List<Account>();
For(Medical_Event_vod__c acc : [SELECT No_of_Speaker_Evaluations__c,(SELECT id FROM Speaker_Evaluations__r) FROM Medical_Event_vod__c WHERE id =: accIdList]){
acc.No_of_Speaker_Evaluations__c = acc.Speaker_Evaluations__c.size();
accUpdateList.add(acc);
}
try{
update accUpdateList;
}Catch(Exception e){
System.debug('Exception :'+e.getMessage());
}
}
Error: Compile Error: Invalid foreign key relationship: Speaker_Evaluation_AEGR__c.Medical_Event_vod__c at line 6 column 27
Please try the below sample code.I have created a custom field NO_of_contacts in account object.when i create a record in contact. No_of_contacts field in related account will be incremented by 1.Replace standard object with your custom objects.
I hope it will help you.
Regards,
Jyothsna D