+ Start a Discussion
Girbson Bijou 8Girbson Bijou 8 

Illegal assignment from Decimal to String at line 34 column 4

Help to solve this please: Illegal assignment from Decimal to String at line 34 column 4 in the test class
public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 
} 
public void search(){ 
string searchquery= 'select Name , FFP_Centers__c,Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  ORDER BY FFP_Centers__c, Prod__c,UM__c Number__c Limi 1000';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 
} 
}


@isTest
private class InventorySearchController_Test{
  @testSetup
  static void setupTestData(){
     test.startTest();
    Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
    Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS', 
    Departement__c = 'NORD', Address__c ='Test Address');
    insert pa;
    
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
          insert cs;
    Container__c container_Obj = new Container__c(Provenance__c = 'FFP FLORIDA', Distribution_Center__c= pa.id, Statut__c = 'Open',  FFP_Centers__c = 'FFP Caracole', 
     RecordTypeId='0126A000000nMlU',  Shipper__c=cs.Id );
    Insert container_Obj; 
    Articles_Containers__c articles_containers_Obj = new Articles_Containers__c(Container__c = container_Obj.id, Number__c = 17, UM__c = 'BAG(S)' ,  Local_ID__c = 7888, Product__c=p.ID,
            Comments__c = 'UNIT(S)',
           Purpose__c='Consignment',
            Condition__c= 'New',
           FFP_Centers__c = 'FFP Caracole'
            );
    Insert articles_containers_Obj; 
    test.stopTest();
  }
  static testMethod void test_search_UseCase1(){
    List<Container__c> container_Obj  =  [SELECT Provenance__c,Statut__c,Is_Reported__c,FFP_Centers__c  from Container__c];
    System.assertEquals(true,container_Obj.size()>0);
    List<Articles_Containers__c> articles_containers_Obj  =  [SELECT Container__c,Number__c,UM__c from Articles_Containers__c];
    System.assertEquals(true,articles_containers_Obj.size()>0);
    InventorySearchController obj01 = new InventorySearchController();
    obj01.inventoryItem = articles_containers_Obj;
 //Illegal assignment from Decimal to String at line 34 column 4      
obj01.searchstring =  articles_containers_Obj[0].Number__c;
    obj01.search();
  }
  static testMethod void test_clear_UseCase1(){
    List<Container__c> container_Obj  =  [SELECT Provenance__c,Statut__c,Is_Reported__c,FFP_Centers__c from Container__c];
    System.assertEquals(true,container_Obj.size()>0);
    List<Articles_Containers__c> articles_containers_Obj  =  [SELECT Container__c,Number__c,UM__c from Articles_Containers__c];
    System.assertEquals(true,articles_containers_Obj.size()>0);
    InventorySearchController obj01 = new InventorySearchController();
    obj01.inventoryItem = articles_containers_Obj;
   // obj01.searchstring = articles_containers_Obj[0].Number__c;
    obj01.clear();
  }
}

 
Best Answer chosen by Girbson Bijou 8
Rameshwar gaurRameshwar gaur
This error coming because you are saving Decimal value in String format.
Convert Your Decimal value in String Format  .
obj01.searchstring =  String.ValueOf(articles_containers_Obj[0].Number__c);