• Laetitia Damen 9
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 5
    Replies
Hi there! 

I'm looking to write a class test for my batch. Any advice? 
 
global class FA_BA_UpdateAccounts implements Database.Batchable<sObject>{
    
   global Database.QueryLocator start(Database.BatchableContext info){ 
       //Requeter seulement les comptes qui ont au moins une commande avec le Status 'Ordered'
       return Database.getQueryLocator('SELECT Id FROM Account WHERE Id In =: (SELECT AccountId FROM Order WHERE Status = \'Ordered\' AND Status = \'Activated\' )');
       
       //new instance of accountQuery
       //FA_QR_Account accountQuery = new FA_QR_Account();
   }
    
   global void execute(Database.BatchableContext info, List<Account> scope){      
    
    FA_QR_Order orderQuery = new FA_QR_Order();     
    
    FA_SRV_Account accountService = new FA_SRV_Account();

    //Call the method getOrders   
    list<Order> listOrders =  orderQuery.getOrders();
       
		for(integer i=0; i < scope.size(); i++){
			Account myAccount = scope[i];
			myAccount.Chiffre_d_affaire__c = 0;
           for(integer j=0; j < listOrders.size(); j++){
               if(listOrders[j].AccountId == myAccount.Id){
                   myAccount.Chiffre_d_affaire__c = myAccount.Chiffre_d_affaire__c + listOrders[j].TotalAmount;
               }                   
           }
       }
       
       
       accountService.updateAccount(scope);

   }    
    
   global void finish(Database.BatchableContext info){     
       
   } 
}

 
I'm looking to create a class test for my query order. It didn't work well.
I've missed something there for sure but I'm pretty new in testing. 
Thanks in advance for your help!
Here is the class then the test class :
 
public with sharing class FA_QR_Order {
    public FA_QR_Order() {

    }
    public AggregateResult getSum () {
        AggregateResult sum = [
            SELECT SUM(TotalAmount) total
            FROM Order];

        return sum;

    }

    public list<Order> getOrders() {
        list<Order> listOrders =  [
            SELECT Id, TotalAmount, AccountId, Status
            FROM Order
        ];

        return listOrders;


    }
}
 
@isTest
public with sharing class TestQueryOrder {
    
    @isTest
    static void TestQueryOrder(){

        Order orderTest = new Order(); 
        orderTest.Status='Ordered';
        orderTest.Name = 'NameTest';
        orderTest.EffectiveDate = System.today();
        orderTest.ShipmentCost__c= 56789;

        insert orderTest;

        list<Order> listOrdersTest = new list<Order>();
        listOrdersTest.add(orderTest);
        
        Test.startTest();
        FA_QR_Order OrderQr = NEW FA_QR_Order();
        listOrdersTest = OrderQr.getOrders(orderTest);
        Order orderTest2= [ SELECT Id, TotalAmount, AccountId, Status FROM Order];

        Test.stopTest();

        System.assertEquals ( listOrdersTest.get(orderTest2));
        
    } 
}

 
Hi There! 

I'm looking to create a class test for my query order. It didn't work well.
I've missed something there for sure but I'm pretty new in testing. 
Thanks in advance for your help!
Here is the class then the test class :
 
public with sharing class FA_QR_Order {
    public FA_QR_Order() {

    }
    public AggregateResult getSum () {
        AggregateResult sum = [
            SELECT SUM(TotalAmount) total
            FROM Order];

        return sum;

    }

    public list<Order> getOrders() {
        list<Order> listOrders =  [
            SELECT Id, TotalAmount, AccountId, Status
            FROM Order
        ];

        return listOrders;


    }
}
 
static void TestQueryOrder(){

        Order orderTest = new Order(); 
        orderTest.Status='Ordered';
        orderTest.Name = 'NameTest';
        orderTest.EffectiveDate = System.today();
        orderTest.ShipmentCost__c= 56789;

        insert orderTest;

        list<Order> listOrdersTest = new list<Order>();
        listOrdersTest.add(orderTest);
        
        Test.startTest();
        FA_QR_Order OrderQr = NEW FA_QR_Order();
        listOrdersTest = OrderQr.getOrders(orderTest);
        Order orderTest2= [ SELECT Id, TotalAmount, AccountId, Status FROM Order];

        Test.stopTest();

        System.assertEquals ( listOrdersTest.get(orderTest2));
        
    } 
}

 
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' );
		
	}
}



 
Hi there !

I'm currently in the test phase of my project. I suppose to write a test on my triggers if someone has the good syntax for that (I've tried but it didn't work): here my triggers
1/

trigger FA_TRH_CalculeAmount on Order (before update) {
for(integer i=0; i< trigger.new.size(); i++){
Order newOrder= trigger.new[i];
newOrder.NetAmount__c = newOrder.TotalAmount - newOrder.ShipmentCost__c;
}
}

2/

trigger FA_TRH_UpdateAccountCA on Order (before insert) {
set<Id> setAccountIds = new set<Id>();
List<Order> ordersList = trigger.new;
FA_QR_Account accountQuery = new FA_QR_Account();
FA_SRV_Account accountService = new FA_SRV_Account();
for(integer i=0; i< trigger.new.size(); i++){
Order newOrder= trigger.new[i];
setAccountIds.add(newOrder.AccountId);
}
Map<Id,Account> mapAccountId = accountQuery.getAccountsByIds(setAccountIds);
List<Account> accToUpdate = new List<Account>();
for (Order order : ordersList){
if(order.Status == 'Ordered' ||order.Status == 'Activated'){
Account acc = mapAccountId.get(order.AccountId);
if(acc != null){
acc.Chiffre_d_affaire__c = acc.Chiffre_d_affaire__c + order.TotalAmount;
}
accToUpdate.add(acc);
}
}
accountService.updateAccount(accToUpdate);
}
Hi there! 

I'd like to test my data from my web-to-lead process (wix website). It creates a lead via WTL. 
Thanks in advance :)
Hi there!
I'm looking for a solution about that case =>
When an opportunity is created, the name must have the following format: Automatic Number – Account Name – Creation Date.
Any advices?  :)
Hi There !
I'm looking to find a way to switch from the lead page to the account page (for the same ID). 
My first option is button & link + visualforce but I'm not really sure about that. 
Any advice ?
Thanks 
Hi there! 
I've merged my javascript button to Aura component (client need). It shows an error. What do I need to change in my code? 
Error while creating a component for lightning component quick action [Assertion Failed!: Abstract component without provider def cannot be instantiated : markup://c:LCC_GenericLightningComponent : undefined] 

Here my code : User-added imageUser-added image

 
Hi there! 

I'm looking to write a class test for my batch. Any advice? 
 
global class FA_BA_UpdateAccounts implements Database.Batchable<sObject>{
    
   global Database.QueryLocator start(Database.BatchableContext info){ 
       //Requeter seulement les comptes qui ont au moins une commande avec le Status 'Ordered'
       return Database.getQueryLocator('SELECT Id FROM Account WHERE Id In =: (SELECT AccountId FROM Order WHERE Status = \'Ordered\' AND Status = \'Activated\' )');
       
       //new instance of accountQuery
       //FA_QR_Account accountQuery = new FA_QR_Account();
   }
    
   global void execute(Database.BatchableContext info, List<Account> scope){      
    
    FA_QR_Order orderQuery = new FA_QR_Order();     
    
    FA_SRV_Account accountService = new FA_SRV_Account();

    //Call the method getOrders   
    list<Order> listOrders =  orderQuery.getOrders();
       
		for(integer i=0; i < scope.size(); i++){
			Account myAccount = scope[i];
			myAccount.Chiffre_d_affaire__c = 0;
           for(integer j=0; j < listOrders.size(); j++){
               if(listOrders[j].AccountId == myAccount.Id){
                   myAccount.Chiffre_d_affaire__c = myAccount.Chiffre_d_affaire__c + listOrders[j].TotalAmount;
               }                   
           }
       }
       
       
       accountService.updateAccount(scope);

   }    
    
   global void finish(Database.BatchableContext info){     
       
   } 
}

 
I'm looking to create a class test for my query order. It didn't work well.
I've missed something there for sure but I'm pretty new in testing. 
Thanks in advance for your help!
Here is the class then the test class :
 
public with sharing class FA_QR_Order {
    public FA_QR_Order() {

    }
    public AggregateResult getSum () {
        AggregateResult sum = [
            SELECT SUM(TotalAmount) total
            FROM Order];

        return sum;

    }

    public list<Order> getOrders() {
        list<Order> listOrders =  [
            SELECT Id, TotalAmount, AccountId, Status
            FROM Order
        ];

        return listOrders;


    }
}
 
@isTest
public with sharing class TestQueryOrder {
    
    @isTest
    static void TestQueryOrder(){

        Order orderTest = new Order(); 
        orderTest.Status='Ordered';
        orderTest.Name = 'NameTest';
        orderTest.EffectiveDate = System.today();
        orderTest.ShipmentCost__c= 56789;

        insert orderTest;

        list<Order> listOrdersTest = new list<Order>();
        listOrdersTest.add(orderTest);
        
        Test.startTest();
        FA_QR_Order OrderQr = NEW FA_QR_Order();
        listOrdersTest = OrderQr.getOrders(orderTest);
        Order orderTest2= [ SELECT Id, TotalAmount, AccountId, Status FROM Order];

        Test.stopTest();

        System.assertEquals ( listOrdersTest.get(orderTest2));
        
    } 
}

 
Hi there !

I'm currently in the test phase of my project. I suppose to write a test on my triggers if someone has the good syntax for that (I've tried but it didn't work): here my triggers
1/

trigger FA_TRH_CalculeAmount on Order (before update) {
for(integer i=0; i< trigger.new.size(); i++){
Order newOrder= trigger.new[i];
newOrder.NetAmount__c = newOrder.TotalAmount - newOrder.ShipmentCost__c;
}
}

2/

trigger FA_TRH_UpdateAccountCA on Order (before insert) {
set<Id> setAccountIds = new set<Id>();
List<Order> ordersList = trigger.new;
FA_QR_Account accountQuery = new FA_QR_Account();
FA_SRV_Account accountService = new FA_SRV_Account();
for(integer i=0; i< trigger.new.size(); i++){
Order newOrder= trigger.new[i];
setAccountIds.add(newOrder.AccountId);
}
Map<Id,Account> mapAccountId = accountQuery.getAccountsByIds(setAccountIds);
List<Account> accToUpdate = new List<Account>();
for (Order order : ordersList){
if(order.Status == 'Ordered' ||order.Status == 'Activated'){
Account acc = mapAccountId.get(order.AccountId);
if(acc != null){
acc.Chiffre_d_affaire__c = acc.Chiffre_d_affaire__c + order.TotalAmount;
}
accToUpdate.add(acc);
}
}
accountService.updateAccount(accToUpdate);
}
Hi there! 

I'd like to test my data from my web-to-lead process (wix website). It creates a lead via WTL. 
Thanks in advance :)
Hi there!
I'm looking for a solution about that case =>
When an opportunity is created, the name must have the following format: Automatic Number – Account Name – Creation Date.
Any advices?  :)