You need to sign in to do that
Don't have an account?

APEX Trigger Coding
Hello, I'm receiving an error message for something that I believe was custom built by our integration partners who are no longer working with us. Below is the message. I can get to the Apex Trigger Page, I just don't know what I should be changing. Can someone advise? Thank you!
Error:Apex trigger kell01_OpportunityTrigger caused an unexpected exception, contact your administrator: kell01_OpportunityTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.AccountId: Trigger.kell01_OpportunityTrigger: line 108, column 1
Error:Apex trigger kell01_OpportunityTrigger caused an unexpected exception, contact your administrator: kell01_OpportunityTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.AccountId: Trigger.kell01_OpportunityTrigger: line 108, column 1
toInsert.add(new Allocation__c(Opportunity__c = opp.Id, Projection__c = projections.containsKey(opp.AccountId) && projections.get(opp.AccountId).containsKey(fy) ? projections.get(opp.AccountId).get(fy).Id : null, Fund__c = primaryFunds.get(opp.Id), Amount__c = opp.Amount));
projections in your code. I would recommend, even code is big copy and paste here. Please do not paste image file. It is tough to debug.
if (trigger.isBefore) { // SetOpportunityHousehold
Set<Id> donorIds = new Set<Id>();
for (Opportunity opp : trigger.new) {
if (opp.AccountId != null) {
donorIds.add(opp.AccountId);
} else {
opp.Household__c = null;
}
}
if (!donorIds.isEmpty()) {
Map<Id, Account> donors = new Map<Id, Account>([SELECT Id, npe01__One2OneContact__r.npo02__Household__c, npe01__One2OneContact__r.npo02__Household__r.Name, npe01__One2OneContact__r.Account.Name
FROM Account WHERE Id IN :donorIds AND npe01__One2OneContact__c != null AND npe01__SYSTEM_AccountType__c != 'Household Account']);
for (Opportunity opp : trigger.new) {
if (opp.AccountId != null && donors.containsKey(opp.AccountId)) {
Account donor = donors.get(opp.AccountId);
opp.Household__c = donor.npe01__One2OneContact__r.npo02__Household__c;
//opp.Household_or_Account_Name__c = donor.npe01__One2OneContact__r.npo02__Household__r.Name != null ? donor.npe01__One2OneContact__r.npo02__Household__r.Name : donor.npe01__One2OneContact__r.Account.Name;
}
}
}
} else if (trigger.isAfter) { // CreateDefaultAllocation
Allocation_Settings__c setting = Allocation_Settings__c.getOrgDefaults();
Set<Id> campaignIds = new Set<Id>();
for (Opportunity opp : trigger.new) campaignIds.add(opp.CampaignId);
Map<Id, Campaign> campaigns = new Map<Id, Campaign>([SELECT Id, Primary_Fund__c FROM Campaign WHERE Id IN :campaignIds]);
Map<Id, List<Allocation__c>> defaultDesignations = new Map<Id, List<Allocation__c>>();
Set<Id> accountIds = new Set<Id>();
Set<String> fiscalYears = new Set<String>();
Integer fyStart = [SELECT Id, FiscalYearStartMonth FROM Organization LIMIT 1].FiscalYearStartMonth;
for (Opportunity opp : trigger.new) {
if (!opp.Do_Not_Update_Projection_Allocations__c) {
accountIds.add(opp.AccountId);
fiscalYears.add(String.valueOf(opp.CloseDate.Year() + (opp.CloseDate.Month() > fyStart && fyStart > 1 ? 1 : 0)));
}
}