• ArunKumar_Remma
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

Hi,

 

    I have a requirement, where in we need to pay the commissions on the payment for the plot in a hierarchial order.  We have written the class which is working perfectly, but when I tried to write the test case for the class, the test case is getting failed.  Can anyone suggest a solution so that the test case get successful with a code coverage above 75% so as migrate the application to the production environment.

 

  I am writing both Apex class and Test case, do look into the code and suggest a solution for the above requirement.

 

 

Apex Class

 

public class paycommissioncontroller {
    
    private ApexPages.StandardController controller {get; set;}
    
     
    public distributor__c d {get;set;}
    public payment__c p;
    static double prevcommpercent;
    static double currentcommamt;
   
    public paycommissioncontroller(ApexPages.StandardController controller)
    {
    this.controller = controller;
    p = (payment__c)controller.getRecord();
    }
 
        
    // method called from the VF's action attribute to clone the Payments
    
    public PageReference paycom() {
    prevcommpercent=0;
    currentcommamt=0;
       
    p=[select id,name,pay__c,plot__c,CUSTOMER__c,No_of_commision__c ,CUSTOMER__r.Customer_Type__c ,Payment_Amount__c,Distributor__c from payment__c where id =:p.id];    
 
 
    // Get all The Commissions already Exist if Any and Delete Them,Every time when "pay commission" is clicked if you want to generate new commissions use following two line and delete next If Condition
    
  
  // Create New Commissions
 
    List<commission__c> createcommission = new List <commission__c> {};
    if (p.CUSTOMER__r.Customer_Type__c == 'agrigold'&& p.Distributor__c!='a0JO0000000e5vq'&& p.No_of_commision__c==0) {
    d=[select id,name,reports_to__c,Eligible_Commission__c from distributor__c where id=:p.distributor__c];
    while(d!=null)
    {
    distributor__c[] ds;
    currentcommamt=(d.Eligible_Commission__c-prevcommpercent);

    prevcommpercent=d.Eligible_Commission__c;

    createcommission.add(new commission__c (DISTRIBUTOR__c=d.id,Payment_Amount__c=p.Payment_Amount__c,
        CUSTOMER__c=p.CUSTOMER__c,Plot_No__c=p.plot__c,PAYMENT_ID__c=p.id,Commission__c=(currentcommamt)));


    ds=[select id,name,reports_to__c,Eligible_Commission__c from distributor__c where id=:d.reports_to__c];
if(ds.size()>0)
{
d=ds[0];
}
else
{
d=null;
}
}
}

    else if(p.CUSTOMER__r.Customer_Type__c == 'CRM'&&p.No_of_commision__c==0){
    d=[select id,name,reports_to__c,Eligible_Commission__c from distributor__c where id=:p.distributor__c];

    distributor__c[] ds;
    prevcommpercent=0;
    currentcommamt=0;
    currentcommamt=18;
    prevcommpercent=18;

createcommission.add(new commission__c (DISTRIBUTOR__c=d.id,Payment_Amount__c=p.Payment_Amount__c,
CUSTOMER__c=p.CUSTOMER__c,Plot_No__c=p.plot__c,PAYMENT_ID__c=p.id,Commission__c=(currentcommamt)));

createcommission.add(new commission__c (DISTRIBUTOR__c='a0JO0000000e5vq',Payment_Amount__c=p.Payment_Amount__c,
CUSTOMER__c=p.CUSTOMER__c,Plot_No__c=p.plot__c,PAYMENT_ID__c=p.id,Commission__c=(5)));

}
insert createcommission;



               return (new ApexPages.StandardController(p)).view();          
           
   
         }
         
         
   }

 

 

TestCase

@isTest

private class PayCommissionControllerTestCase{

static testmethod void testPayCommissionController()
   {
          
      ApexPages.StandardController con = new ApexPages.StandardController(new Payment__c());
  
      PayCommissionController pcc = new PayCommissionController(con);
      
      PageReference pr1 = pcc.paycom();
         
       
   }

}

 

 

     For the above Testcase I am getting a code coverage of 35% and also the testcase is failing, therefore I request you people to suggestion some solution so that the test case is successful and code coverage is above 75 %.

 

 

 

 

Thanks and Regards

 

Arun

Hi All,

 

    I have a requirement where in i need to print a field called Appointment ID in VisualForce Page.  This field should be displayed with hyperlink, so that when we click on this field link, we should navigate to that particular Appointment.  Could any one suggest a solution for this problem.

 

 

 

Thanks & Regards

 

Arun

Hi All,

 

    We have written an application to implement SMS feature in salesforce.  The application is running successfully, but when I am writing test case, the test case is successful but the code coverage is 54%.  But, in order to migrate the code we are suppose to have a code coverage of 75 %. 

 

   Therefore I request you people to kindly suggest some solution, so that the code coverage is greater than 75 %.

 

   I am posting both the class and testcase, do kindly suggest a solution.

 

 

 

Apex Class

 

 

public class DEV_Send_SMS{

    private ApexPages.StandardController controller {get; set;}

    private  task parOrd;
    Private account acc;
    public DEV_Send_SMS(ApexPages.StandardController Controller) {
    
    this.controller = controller;

    parOrd=(task)Controller.getrecord();
              
    }

public Pagereference pageredir() {
     
   
    task t=[select id, description, Dev_Send_SMS__c, who.type, whoid
                 from task where id =:parOrd.id and who.type='contact'];  
            
    contact c =[select id, name,MobilePhone, phone from contact
                        where id =:t.whoid];
    
    String s = 'http://www.rediworkz.com/sms/apisendsmsbulk.php?type=0&from=60122173031&to=' + c.MobilePhone + '&text=' + t.Description + '&user=60122173031&pass=rick2345&senderid=VISTA&gateway=9';
       
    return t.Dev_Send_SMS__c == 'yes' ? new PageReference(s) : null;
            
        }
}

 

TestCase:

 

 

@isTest
private class DEV_Send_SMSTestCase
{

   static testMethod void MyMethod()
   {

 

           Task t1 = new Task();
      
       ApexPages.StandardController con = new ApexPages.StandardController(t1);
      
       Task parOrd = (Task)con.getRecord();
      
      DEV_Send_SMS sms1 = new DEV_Send_SMS(con);
     
//  sms1.pageredir();
 
      
  }

 

 

  Note:  If  I am enabling the last statement in the TestCase (sms1.pageredir();

 

              I am getting a code coverage of 72% ,   but the TestCase is getting failed.  So kindly provide a solution.   



Regards

 

 

Arun

      
     

Hi All,

 

    We have written an apex class for multiple line items, but facing problem in writing the test case for the same.  So, could any one please suggest a solution to the making the test case successful. 

 

 

Apex Code:

 

 

public class DEV_MULTIPLE_InvoiceLineEntry {

    public List<Invoice_Line_Item__c> ords {get; set;}
    private final Invoice__c parOrd;
    public DEV_MULTIPLE_InvoiceLineEntry(ApexPages.StandardController myController) {
        parOrd=(Invoice__c)myController.getrecord();
        ords = new List<Invoice_Line_Item__c>();
         // Get the Current User
     user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];
     
     // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
        if(u1.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
       
        ords.add(LitOrd);
         
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
        else if(u1.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w1[0].id;
        ords.add(LitOrd);
        }
        }
        
       

    public void addrow() {
    
        // Get the Current User
     user u =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w =[select id,name from Warehouse__c where name =: u.Formula_Warehouse__c];
         // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
     if(u.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.Quantity__c=1;
       
        ords.add(LitOrd);
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
                
        else if(u.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w[0].id;
        ords.add(LitOrd);
        
        }   
           
        }  
           
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
       // PageReference home = new PageReference('/home/home.jsp');
        return(new ApexPages.StandardController(parOrd)).view();
       // home.setRedirect(true);
       // return home;
         }
        
        }

 

 

 

Thanks and Regards

 

Arun

Hi All,

 

    We have written an apex class for multiple line items, but facing problem in writing the test case for the same.  So, could any one please suggest a solution to the making the test case successful. 

 

 

Apex Code:

 

 

public class DEV_MULTIPLE_InvoiceLineEntry {

    public List<Invoice_Line_Item__c> ords {get; set;}
    private final Invoice__c parOrd;
    public DEV_MULTIPLE_InvoiceLineEntry(ApexPages.StandardController myController) {
        parOrd=(Invoice__c)myController.getrecord();
        ords = new List<Invoice_Line_Item__c>();
         // Get the Current User
     user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];
     
     // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
        if(u1.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
       
        ords.add(LitOrd);
         
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
        else if(u1.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w1[0].id;
        ords.add(LitOrd);
        }
        }
        
       

    public void addrow() {
    
        // Get the Current User
     user u =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w =[select id,name from Warehouse__c where name =: u.Formula_Warehouse__c];
         // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
     if(u.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.Quantity__c=1;
       
        ords.add(LitOrd);
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
                
        else if(u.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w[0].id;
        ords.add(LitOrd);
        
        }   
           
        }  
           
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
       // PageReference home = new PageReference('/home/home.jsp');
        return(new ApexPages.StandardController(parOrd)).view();
       // home.setRedirect(true);
       // return home;
         }
        
        }

 

 

 

Thanks and Regards

 

Arun

 Hi

 

Do you know if it's possible (via Partner WSDL) new Custom Object in Salesforce ?

How ? (need a code snippet)

 

Thanks

 

Hagai

  • September 22, 2010
  • Like
  • 0