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
Subramani_SFDCSubramani_SFDC 

Need test method

global class getProductDetail
{

  
    
    WebService static List<string> getProductUpdate(List<Product2> lstPro)
    {
            List<string> lstProName = new List<string>();
            List<Product2> Productlist = new List<Product2>();
          //  List<Product2> prod=new  List<Product2>();
          Product2 pro = new  Product2();
            system.debug('---------------Name----------------'+lstPro);
             system.debug('---------------Name----------------'+lstPro[0].Name);
             system.debug('---------------strname__c----------------'+  lstPro[0].strOnhand__c);
             system.debug('---------------strname__c----------------'+  lstPro[0].QB_Available__c);
             
            for(Product2 p: lstPro)
            {
                try 
                {
            
                   pro =[Select Name,Family,ProductCode,QB_Available__c,QB_Next_due_date__c,QB_On_Hand__c,QB_On_order__c,QB_On_sales_order__c from Product2 where ProductCode=:p.Name and Family != 'Retail'];
                  
                  
                       system.debug('---------------Name----------------'+ pro.Name);
                       pro.QB_Available__c = Decimal.valueof(p.strAvailable__c);
                      system.debug('---------------Available----------------'+ pro.QB_Available__c);
                       pro.QB_On_Hand__c = Decimal.valueof(p.strOnhand__c);
                       pro.QB_On_order__c= Decimal.valueof(p.strOnOrder__c);
                       pro.QB_On_sales_order__c= Decimal.valueof(p.strOnOrderSales__c);
                       if(p.strNextDewDate__c != null)
                       pro.QB_Next_due_date__c= Date.valueof(p.strNextDewDate__c);
                     
                     
                      update pro;
                      string strname = 'Updated successfully:  '+p.Name;
                      lstProName.add(strname );
                  
               }
                catch(Exception e) 
                { 
                   System.debug('The following exception has occurred: '+p.Name + e.getMessage());
                   string pname = 'Update Failed -Error:' +p.Name+ e ;
                   lstProName.add(pname);
                } 
                  
             
            
            } 
            
          
           // Update Productlist;
            system.debug('---------------ProductUpdated----------------');
        
            return lstProName ;
    }
    
}

Best Answer chosen by Admin (Salesforce Developers) 
Subhash GarhwalSubhash Garhwal

Hi,

Please provide Product2's field values as your requirement

 

@isTest
private class Test_GetProductUpdate {

static testMethod void myUnitTest() {


List<Product2> pros = new List<Product2>();

 

pros.add(new Product2(Name = '123', ProductCode = '123', Family = 'Test'));
pros.add(new Product2(Name = 'Test 1', ProductCode = '1234'));

 

insert pros;

 

//Start Testing from here
Test.startTest();

 

getProductDetail.getProductUpdate(pros);

 

//Stop Test here
Test.stopTest();

}
}

 

For more help

 

Go for this post , it will definetly helps you out

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

 

Thanks,

 

Hit the Kudos button (star) if it post helps you

All Answers

Subhash GarhwalSubhash Garhwal

Hi,

Please provide Product2's field values as your requirement

 

@isTest
private class Test_GetProductUpdate {

static testMethod void myUnitTest() {


List<Product2> pros = new List<Product2>();

 

pros.add(new Product2(Name = '123', ProductCode = '123', Family = 'Test'));
pros.add(new Product2(Name = 'Test 1', ProductCode = '1234'));

 

insert pros;

 

//Start Testing from here
Test.startTest();

 

getProductDetail.getProductUpdate(pros);

 

//Stop Test here
Test.stopTest();

}
}

 

For more help

 

Go for this post , it will definetly helps you out

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

 

Thanks,

 

Hit the Kudos button (star) if it post helps you

This was selected as the best answer
Subramani_SFDCSubramani_SFDC

it gives 60%...thanks a lot..i will make it  100%...thanks