You need to sign in to do that
Don't have an account?
Chandu007
Is it mandatory to use SeeAllData=true to get Pricebookentry object in test class?
I am doing some modifications to existing test class and removed SeeAllData=true(for best practise). now i am getting below error. So, now i want to know whether SeeAllData=true when we are using Pricebook object in test class.
Error:-
System.QueryException: List has no rows for assignment to SObject
errored line from test class:-
Pricebook2 pb = [select Id from Pricebook2 where isStandard=true limit 1];
Error:-
System.QueryException: List has no rows for assignment to SObject
errored line from test class:-
Pricebook2 pb = [select Id from Pricebook2 where isStandard=true limit 1];
Greetings to you!
You can use Test.getStandardPricebookId() to get the Id of the current Pricebook.
Below is the sample code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I have modified my test class as you suggested above but it failing again with below error and trigger CMDM_Post_Tention_Weight_Rollup is another trigger which is not currently i am working.
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CMDM_Post_Tention_Weight_Rollup: execution of AfterInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.CMDM_Post_Tention_Weight_Rollup: line 4, column 1: []