I'm getting an odd error when trying to pull a value in a list. I know the error is due to no rows however it fires the exception on row 0 which is odd to me. Any help would be great.
Here is the error I'm getting
System.DmlException: Update failed. First exception on row 0 with id a0f2F000000ElPBQA0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, HomeDepotStore: execution of BeforeUpdate
caused by: System.QueryException: List has no rows for assignment to SObject Class.HomeDepotStoreHandler.beforeUpdate: line 6, column 1
Class.TriggerHandler.run: line 41, column 1 Trigger.HomeDepotStore: line 2, column 1: []
Here is my Trigger
trigger HomeDepotStore on i360__Sale__c(before insert, before update) {
new HomeDepotStoreHandler().run();
}
Here is my Trigger Handler Class
public class HomeDepotStoreHandler extends TriggerHandler {
public HomeDepotStoreHandler() {}
public override void beforeUpdate() {
i360__Sale__c a = new i360__Sale__c();
List <i360__Staff__c> staffid = [select id from i360__Staff__c where
i360__Staff__c.Name =: a.Referral_Store__c];
if (a.HD_Base_Store_Our_System__c == null) {
a.HD_Base_Store_Our_System__c = staffid.get(0).Id;
}
System.debug(LoggingLevel.INFO, 'HD Base Store Our System:' +
a.HD_Base_Store_Our_System__c);
}
}
Here is my Test Class
@isTest
private class HomeDepotStoreTest {
static testMethod void TestHomeDepotStores() {
i360__Staff__c staff = new i360__Staff__c();
staff.Name = '2036';
staff.i360__Start__c = Date.today();
insert staff;
i360__Staff__c salesrep = new i360__Staff__c();
salesrep.Name = 'Mike Levitzke';
salesrep.i360__Start__c = Date.today();
salesrep.i360__Position_Title__c = 'Sales Res';
insert salesrep;
i360__Prospect__c Pros = new i360__Prospect__c();
Pros.Name ='Bob Joe';
Pros.Referral_Store__c = '2036';
Pros.i360__Phone_1__c = '(123) 123-1234';
Pros.i360__Primary_Last_Name__c = 'TESTMCTEST';
insert Pros;
i360__Marketing_Source__c source = new i360__Marketing_Source__c();
source.i360__Type__c = 'Amazon Services';
source.i360__Start__c = Date.today();
source.i360__End__c = Date.today().addYears(1);
insert source;
i360__Lead_Source__c leadsource = new i360__Lead_Source__c();
leadsource.i360__Source__c = source.Id;
leadsource.i360__Prospect__c = Pros.Id;
leadsource.i360__Taken_On__c = Date.today();
insert leadsource;
i360__Appointment__c App = new i360__Appointment__c();
App.Name = '2036';
App.i360__Prospect__c = Pros.Id;
App.i360__Lead_Source__c = leadsource.Id;
App.i360__Start__c = Date.today();
App.i360__Sales_Rep_1__c = salesrep.Id;
insert App;
i360__Sale__c a = new i360__Sale__c();
a.Name ='2036';
a.i360__Appointment__c = App.Id;
insert a;
a.i360__Email_Address__c = '[email protected]';
update a;
}
}
where i360__Staff__c.Name =: a.Referral_Store__c
this looks suspect,a
is a new record that hasn't been inserted yet, what are you expectinga.Referral_Store__c
to be at this point in the code?