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
RajnisfRajnisf 

List has no rows for assignment to SObject!!!

@isTest
private class tprotest {


     @isTest static void testCallout() {   
                          
           Account acc = new Account(name = 'test', ia_crm__Sync_With_Intacct__c = true ,ia_crm__IntacctID__c = 'C111',Phone = '33333344444', 
 billingstreet = '4th avenue', billingcity = 'tampa',billingstate = 'FL',  billingcountry = 'United States', BillingPostalCode = '11001', Description = 'javascript :: null');
 insert acc;

          Opportunity op = new Opportunity(
          Name = 'Prasadam',                       
          Accountid = acc.id,                      
          IsPrivate = false,                       
          Amount = 1000.00,
          StageName = 'Contract Signed',                
          CloseDate = Date.parse('09/09/2019'),  
          Probability = 100  ,      
          Card_Holder_s_Name__c =   'rajni bala',
          Credit_Card_Number__c = '5446886522351236',
         Credit_Card_Expiration_Date__c = '07/2019',    
          Routing_Number__c = '123556985',
          Accounting_Number__c = '445669',
          TPro_Success__c = 'true',
          TPro_AuthID__c = null,
          TPro_CC_StoredAccountID__c = null,
          Billing_First_Name__c = 'Anna',
          Billing_Last_Name__c ='Jordan',
          Billing_Contact_Email__c = 'anna@jumpcrew.com'
        //  test__c = 'C111'
          );
          
         insert op;


         
    }                  
            //op.Routing_Number__c = '552236996';
           // op.Credit_Card_Number__c= '5546886522351236';
          //  op.Account.Name = 'testacc';
    
 
                // Set mock callout class 
                  
   @isTest static void testCalloutt(){
   
   Opportunity opp = [Select Id, Name FROM Opportunity WHERE Name = 'Prasadam' Limit 1];
      
   Test.setMock(HttpCalloutMock.class, new MocktProOpportunity()); 
   
                 Test.startTest();
               new tproOpportunityTriggerHandler().sendCardToTPro(opp);
               tproOpportunityTriggerHandler.send(opp.Id);             
            
                Test.stopTest(); 
                opp = [SELECT Id,Accountid, Card_Holder_s_Name__c,Credit_Card_Number__c,Credit_Card_Expiration_Date__c,Account.ia_crm__IntacctID__c,  Account.Name, test__c,Billing_Contact_Email__c,
              Event_Code__c,Routing_Number__c,Accounting_Number__c,TPro_Success__c,TPro_AuthID__c,StageName ,TPro_CC_StoredAccountID__c
             FROM Opportunity where id =: opp.Id];
             
             System.assertEquals('Prasadam', opp.Name ); 
             System.assertEquals('Contract Signed', opp.StageName ); 
             
           
 
}
      
}
Problem is here...   Opportunity opp = [Select Id, Name FROM Opportunity WHERE Name = 'Prasadam' Limit 1];

2nd problem is : System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Best Answer chosen by Rajnisf
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi rajnisf, 

Change the line 5 from @isTest static void testCallout() to @testSetup static void testCallout() and check.

Thanks and regards, 
Prosenjit Sarkar  

All Answers

Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi rajnisf, 

Change the line 5 from @isTest static void testCallout() to @testSetup static void testCallout() and check.

Thanks and regards, 
Prosenjit Sarkar  
This was selected as the best answer
RajnisfRajnisf
thanks a lot!!