function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
uday kiran 216uday kiran 216 

System.QueryException: List has no rows for assignment to SObjects

Test.starttest();
List<Database.DeleteResult> result2 = Database.delete(oppList, false);
LogDAO.logDatabaseError(result2, 'LagDAO:deleteResult');
Test.stopTest();

system.assertequals(true, opp.Id !=null); 
String errMsg = 'Your attempt to delete Test Opp could not be completed beacuse it is associated with the follow opportunity information.'; 
System.assert(([SELECT Details__c from Log__c Where ExcceptionType__c = 'Delete_Failed' LIMIT 1]. Details__c).contains(errMsg));
SwethaSwetha (Salesforce Developers) 
HI Uday,
As the error suggests, can you check if the SOQL query returns any records?

The article https://help.salesforce.com/articleView?id=000328824&type=1&mode=1 should help.

If this information helps, please mark the answer as best. Thank you
mukesh guptamukesh gupta
Hi Uday,

Please use below code:-
 
Test.starttest();
List<Database.DeleteResult> result2 = Database.delete(oppList, false);
LogDAO.logDatabaseError(result2, 'LagDAO:deleteResult');
Test.stopTest();

system.assertequals(true, opp.Id !=null); 
String errMsg = 'Your attempt to delete Test Opp could not be completed beacuse it is associated with the follow opportunity information.'; 


String str='%'+errMsg+'%';


ExcceptionType__c  obj =  [SELECT Details__c from Log__c Where ExcceptionType__c = 'Delete_Failed' AND Details__c LIKE str  LIMIT 1];

if(obj != null){
  // Add here logic
}
if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh


 
Prachi Gadewar 12Prachi Gadewar 12
Hi Uday,

Here is modified code, as per my understanding

Test.starttest();
List<Database.DeleteResult> result2 = Database.delete(oppList, false);
LogDAO.logDatabaseError(result2, 'LagDAO:deleteResult');
Test.stopTest();

/* just one doubt, from where you are fetching this record "opp"?*/
system.assertequals(true, opp.Id !=null); 

String errMsg = '%Your attempt to delete Test Opp could not be completed beacuse it is associated with the follow opportunity information.%'; 
Log__c logRecord = [SELECT Details__c from Log__c Where ExcceptionType__c = 'Delete_Failed' and Details__c LIKE: errMsg LIMIT 1];
System.assert(logRecord != null);