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
Laetitia Damen 9Laetitia Damen 9 

Test SOQL !

Hi there!

I've tried to test my query Account class but in vs code it displays : 
=== Test Summary
NAME VALUE
─────────────────── ───────────────────────
Outcome Skipped

Here is my class & my class test, if someone gets an idea? 
public with sharing class FA_QR_Account {
    public FA_QR_Account() {

    }
    
    public Map<Id,Account> getAccountsByIds(set<Id> setAccountIds) {
        Map<Id,Account> mapAccountId = new Map<Id,Account> ([
            SELECT Id, Chiffre_d_affaire__c 
            FROM Account 
            WHERE Id in:setAccountIds 
        ]);

        return mapAccountId;
    }

}


 
@isTest
public class TestFA_QR_AccountTest 
{ 
    @isTest
    static testMethod void testgetAccountsByIds() 
	{
		
        // Add all required field
        Map<Id,Account> mapAccountId = new Map<Id,Account>;
        for(String count =0; count<0; count++){
           mapAccountId.add(new Account (Name = 'Jack'+count, Chiffre_d_affaire__c = '20000', Id = '0011U00000TFV7M' ,+count)); 
        }
        insert mapAccountId;
		

        Test.startTest();

		FA_QR_Account.getAccountsByIds();
		
        Test.stopTest();

        Account acc= [SELECT Id FROM Account LIMIT 1];
        
		System.assertEquals (String.valueOf(acc.Id),'0011U00000TFV7M' );
		
	}
}



 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Please modify the test class as below

 
@isTest
public class TestFA_QR_AccountTest 
{ 
   // @isTest
    static testMethod void testgetAccountsByIds() 
    {
        
    List<Account> accounts = new List<Account>();
 
  Account acc= new Account(Name = 'Jack', Chiffre_d_affaire__c = '20000');
        
    insert acc;
   Map<Id,Account> mapAccountId = new Map<Id,Account>();
        set<id> accountid= new set<id>();
        accountid.add(acc.id);
    Test.startTest();
        FA_QR_Account ACCOCU= NEW FA_QR_Account();
      mapAccountId =  ACCOCU.getAccountsByIds(accountid);
        Account account1= [select id,Chiffre_d_affaire__c from Account where id in :accountid];
    Test.stopTest();
        System.assertEquals ( mapAccountId.get(acc.id) ,account1 );
    
}
}
        


If this solution helps, Please mark it as best answer.

Thanks,

 
Suraj Tripathi 47Suraj Tripathi 47
Hi Laetitia Damen,
Use this code in your Test Class :
@isTest
public class TestFA_QR_AccountTest 
{ 
    @isTest
    static void testgetAccountsByIds() 
    {
    List<account> accList = new List<account>();
    Set<id> accIdSet = new Set<id>();
       for(Integer i=0 ; i<2;i++)
    {
    account acc = new account();
    acc.Name = 'acc'+i;
    accList.add(acc);
    }
    insert accList;
    for(account acc:accList){
    accIdSet.add(acc.id);
    }        

        Test.startTest();
        FA_QR_Account.getAccountsByIds(accIdSet);
        Test.stopTest();

//Use System.assertEquals() according to your Condition.
    }
}

If you find your Solution then mark this as the best answer.

Thank you!
Regards,
Suraj Tripathi