+ Start a Discussion
anurajanuraj 

test class

i am writing a test class on this trigger 

rigger FillAccountandProduct on BBB_Transactions__c (before insert)
{
Set<String> productNames = new Set<String>();
Set<String> AccntNames = new Set<String>();

Map<String,integer> producttoSAPId=new Map<String,integer>();
Map<String,integer> accnttoSAPId=new Map<String,integer>(); 
  for (BBB_Transactions__c Btr : Trigger.new) 
    {    
      productNames.add(Btr.Product__c);
      AccntNames.add(Btr.Forecasted_Customer__c);
      
    }
   for(Product2 Pr:[Select p.Name,p.SAP_ID__c from Product2 p where p.Name in :productNames])
  {       
      producttoSAPId.put(Pr.Name,integer.valueOf(Pr.SAP_ID__c));
      
      
  }    
    for(Account a:[Select p.R90_Account_Name__c,p.SAP_ID__c from Account p where p.R90_Account_Name__c in :AccntNames])
  {       
      accnttoSAPId.put(a.R90_Account_Name__c,integer.valueOf(a.SAP_ID__c));      
  } 
    for (BBB_Transactions__c Btr : Trigger.new) 
    {
      Btr.SAP_Account_ID__c=accnttoSAPId.get(Btr.Forecasted_Customer__c);
      Btr.SAP_Product_ID__c=producttoSAPId.get(Btr.Product__c);
    }
    
}

 I wrote it like this

@isTest
public class TestFillAccountandProduct 
{
  static testmethod void testAccountandProduct()
  {
     String strRecordTypeIdItem = [Select Id, Name From RecordType Where SobjectType = 'Account' and Name = 'SAP Customer'].id;
     BBB_Transactions__c bbt = new BBB_Transactions__c();
     bbt.Product__c = 'bbproduct';
     bbt.Forecasted_Customer__c = 'bbforcast';
     bbt.Name = 'bbName';
     insert bbt;
     
     Product2 p = new Product2();
     p.Name = bbt.id;
     p.SAP_ID__c = 'pSapId';
     insert p;
     
     list< product2> pr2 = new list< product2>();
     pr2 = [select SAP_ID__c, name from product2 where name = :bbt.Product__c]; 
     
     Account a = new Account();
    // a.R90_Account_Name__c = bbt.id;
     a.Name = 'aName';
     a.Has_customer_been_contacted_or_visite__c  = 'ahasC';
     a.SAP_ID__c = 'aSname';
     a.RecordTypeId = strRecordTypeIdItem; 
     a.Location_Type__c = 'aLocation';
     insert a;
     
     list<Account> ac = new list<Account>();
     ac = [Select SAP_ID__c, R90_Account_Name__c from account where  R90_Account_Name__c = :bbt.Forecasted_Customer__c];
     
     list<BBB_Transactions__c> bt = new list<BBB_Transactions__c>();
     bt = [Select Product__c, Forecasted_Customer__c, SAP_Account_ID__c , SAP_Product_ID__c   from BBB_Transactions__c where id= :bbt.id];
     
    // bt[0].SAP_Product_ID__c  = bt[0].Forecasted_Customer__c;
    // bt[0].SAP_Account_ID__c  = bt[0].Product__c;
    // update bt;
     //system.assertEquals(bt[0].SAP_Account_ID__c, bt[0].Forecasted_Customer__c);
     //system.assertequals(bbt.SAP_Product_ID__c, bbt.Product__c);
   }
}

 but it have some error and need some changes which i am not able to make 

please help me 

 

Thanks

Anuraj

Andy BoettcherAndy Boettcher

What is your error?

anurajanuraj

no coverage and cannot able to assert 

anurajanuraj

thanks for your replay

here sap_account__c is id and forecast_customer__ is a text data type

system.assertEquals(bt[0].SAP_Account_ID__c, bt[0].Forecasted_Customer__c);
     //system.assertequals(bbt.SAP_Product_ID__c, bbt.Product__c);