You need to sign in to do that
Don't have an account?
sfdc13
can some one help me how to test this query
I am getting Error:System.QueryException: List has no rows for assignment to SObject
public String save(String ids){
Case caseObject = [SELECT Subject, Description, ContactId, Origin, Priority, Status, OwnerId, RecordTypeId, ParentId, Product_Code__c,Product_Description__c, Lot_Number__c, GMP_Quality__c, Trademark__c, Business_Unit__c, ProdCert_Topic__c,Rega_Responsibility__c,ProdCert_Request__c,Business_Line_Description__c,Additional_Request_Info__c,Applied_ProdCert_Rule__c,RAAnswer__c FROM Case where Id =: ids];
public String save(String ids){
Case caseObject = [SELECT Subject, Description, ContactId, Origin, Priority, Status, OwnerId, RecordTypeId, ParentId, Product_Code__c,Product_Description__c, Lot_Number__c, GMP_Quality__c, Trademark__c, Business_Unit__c, ProdCert_Topic__c,Rega_Responsibility__c,ProdCert_Request__c,Business_Line_Description__c,Additional_Request_Info__c,Applied_ProdCert_Rule__c,RAAnswer__c FROM Case where Id =: ids];
Here is the dummy data which I am providing in this test class, I have provided all these standards fields but the custom fields which you are using in your SOQL query you need to create records for those custom fields by using the same you can cover your 'save' method SOQL query using test class:
Note:- 'ApexClassName' this is going to be your Name of Apex class.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
Use the below code
Try this code it will work.
Thanks!
Vikash
- I implemented it in my Org and code is running fine. Please use the below code :
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
Your query is not bulkify that why it throws this exception 'Error:System.QueryException: List has no rows for assignment to SObject'.Try the following code it may helpful for you and for more info about this exception follow the given link-https://help.salesforce.com/articleView?id=000328824&type=1:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
thanks to everyone, Actually I am getting an error when I run my test class I need to cover that query in a test class Please give me any suggestions
Here is the dummy data which I am providing in this test class, I have provided all these standards fields but the custom fields which you are using in your SOQL query you need to create records for those custom fields by using the same you can cover your 'save' method SOQL query using test class:
Note:- 'ApexClassName' this is going to be your Name of Apex class.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi