You need to sign in to do that
Don't have an account?
test method for SOQL
hi i have a query i n my controller as DataLoadTest__c selectedRecord = [select Id,name,city__c,country__c,phone__c from DataLoadTest__c where id=:rId limit 1]; how to write test method for this query. it showing exception as System.QueryException: List has no rows for assignment to SObject
You'll need to create a record that satisfies the criteria as part of your test.
HI,
You have to simply insert a record DataLoadTest__c inside the test method before calling that function.
DataLoadTest__c d=new DataLoadTest__c(name=’test’, other mendatory fields);
Insert d;
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
i created a record, but still its showing same exception
i created a record, but still its showing same exception
Did you create the record as part of the test, or did you create it in the org (e.g. via the UI)?
Y have a where clause... remove it from query or ensure that the criteria is satisfied with the record y created.... otherwise it will return no rows
if you do like below it will return a record
DataLoadTest__c yourRecord = new DataLoadTest__c();
Id rId = yourRecord.id
DataLoadTest__c selectedRecord = [select Id,name,city__c,country__c,phone__c from DataLoadTest__c where id=:rId limit 1];
i created in test method also.
Can you please copy your exact class here, so we can give the exact code.
You haven't set the record id into the controller. You also seem to have roid and rid in the controller - I'm guessing its the rid that needs to be set up but I could be wrong: