You need to sign in to do that
Don't have an account?
Sonam Patil
Apex codeTest class Exception
Hi,
Below is my code for the test class.
I am getting this Exception,
System.sObjectException:sObject row was retrieved via SOQL without querying the required field:Book__c.Price__c.
Below is my code for the test class.
I am getting this Exception,
System.sObjectException:sObject row was retrieved via SOQL without querying the required field:Book__c.Price__c.
Please, can anyone help me?
@isTest
public class BookTest {
public static @isTest void btest(){
Book__c b = new Book__c(Name='Kcloud',
price__c=100);
System.debug('The price of a book before insert is:'+b.Price__c);
insert b;
b=[Select id,Name from Book__c where id=:b.id];
System.debug('The price of the book after thr trigger is fired:'+b.Price__c);
System.assertEquals(90,b.price__c);
}
}
@isTest
public class BookTest {
public static @isTest void btest(){
Book__c b = new Book__c(Name='Kcloud',
price__c=100);
System.debug('The price of a book before insert is:'+b.Price__c);
insert b;
b=[Select id,Name from Book__c where id=:b.id];
System.debug('The price of the book after thr trigger is fired:'+b.Price__c);
System.assertEquals(90,b.price__c);
}
}
This is because you are using price__c without querying. Try this code : Regards,
Ajay
But, now I am getting this error:
System.AssertExceptin:AssertionFailed