You need to sign in to do that
Don't have an account?
Newbie 2014
Errors to Delete records
Hello: I have a simplest test class to delete a single record, code below. I have checked the select statement via 'query editor' in developer console; it returns a valid id. I just can't figure out why my delete statement does not work! My class passes the test alright, but when I go and check the line item under the parent opportunity, I can see the line item is there unaffected. Please advise! Thanks very much
@istest
public class del1
{
static testmethod void unittest() {
List<opportunitylineitem> ol = [select id from opportunitylineitem where id =: '00km0000001WVUSAA4'] ;
delete ol;
}
}
@istest
public class del1
{
static testmethod void unittest() {
List<opportunitylineitem> ol = [select id from opportunitylineitem where id =: '00km0000001WVUSAA4'] ;
delete ol;
}
}
Try this,You are not making seealldata = true ,So query can't find record.But this is not good way to write testclass,Insert some dummy record in test class and than delete ,If you write test like below way making id hardcoded,Test class will be failed in another instance.
@istest(SeeAllData = True )
public class del1
{
static testmethod void unittest() {
List<opportunitylineitem> ol = [select id from opportunitylineitem where id =: '00km0000001WVUSAA4'] ;
delete ol;
}
}
If My solution work for you ,Please mark as Like and resolved.
Thanks,
Anil Savaliya
I agree with you wholeheartedly about not to hardcode. This is just a test class to test one trigger on the object so..
public class del1
{
static testmethod void unittest() {
opportunitylineitem OTLL = New opportunitylineitem ();
(Add All required Field for opportunitylineitem like OTLL.Name = 'Test Test '; etc etc.)
Insert OTLL;
Delete OTLL;
}
}
Thanks for trying to help I'd say. Take care, Newbie