You need to sign in to do that
Don't have an account?
DannyTK
Receiving an Invalid field initializer error on Test Class
Good afternoon,
I'm trying to write a test class for a trigger where if there's an open Task on a record (custom object, Sales_Order__c), then the status of the record (Sales Order) = "Pending Question". When the task is complete, then the status updates to "Ready for Review". The trigger works fine, but I can't seem to get the test class to save:
@isTest
private class TriggerSalesOrderUpdateonTask {
static testMethod void validateTriggerSalesOrderUpdateonTask () {
List<Sales_Order__c> so = new List<Sales_Order__c> {new Sales_Order__c (
so.name = '000001')};
insert so;
List<task> t = new List<task> {new task(
WhatID = Sales_Order__c[0].id,
subject = 'test trigger',
Status = 'Not Started')};
insert t;
List<task> taskstoupdate = New List<task>{[select id from task where id in :t]};
for (task tok:taskstoupdate)
tok.Status = 'Completed';
update taskstoupdate;
system.assertEquals(so.Status__c, 'Sales Order Ready for Review');
}
}
I'm receiving a Compile Error: Invalid field initializer:so.name at line 6 column 7. Can someone take a look and see where i'm going wrong, and let me know if you need me to post my trigger on here as well. Thanks community.
I'm trying to write a test class for a trigger where if there's an open Task on a record (custom object, Sales_Order__c), then the status of the record (Sales Order) = "Pending Question". When the task is complete, then the status updates to "Ready for Review". The trigger works fine, but I can't seem to get the test class to save:
@isTest
private class TriggerSalesOrderUpdateonTask {
static testMethod void validateTriggerSalesOrderUpdateonTask () {
List<Sales_Order__c> so = new List<Sales_Order__c> {new Sales_Order__c (
so.name = '000001')};
insert so;
List<task> t = new List<task> {new task(
WhatID = Sales_Order__c[0].id,
subject = 'test trigger',
Status = 'Not Started')};
insert t;
List<task> taskstoupdate = New List<task>{[select id from task where id in :t]};
for (task tok:taskstoupdate)
tok.Status = 'Completed';
update taskstoupdate;
system.assertEquals(so.Status__c, 'Sales Order Ready for Review');
}
}
I'm receiving a Compile Error: Invalid field initializer:so.name at line 6 column 7. Can someone take a look and see where i'm going wrong, and let me know if you need me to post my trigger on here as well. Thanks community.
All Answers
so i made the following updates to bypass the various error messages:
1) updated line 6 to name='000001', had to change to Status__c = 'Sales Order Submitted' (Name isn't a writable field)
2) updated WhatID = Sales_Order__c[0].id to so[0].id
looks like now the "system.assertEquals(so.Status__c, 'Sales Order Ready for Review');" line is throwing a "Initial term of field expression must be a concrete SObject:List<Sales_Order__c> " error
should i now have used the List command, or is there a way to change the last line to be consistent to bypass this error....didn't realize that my test class was that far off...