• beatit
  • NEWBIE
  • 0 Points
  • Member since 2010

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

 

public class PlotWithrelatedpaymentsController {
    //Testing from IDE
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
    
     // add the instance for the variables being passed by id on the url
    private plot__c po {get;set;}
    private plot__c newpo {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}
 
    // initialize the controller
    public PlotWithrelatedpaymentsController(ApexPages.StandardController controller) {
 
        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        po = (plot__c)controller.getRecord();
        //newpo = (plot__c)controller.getRecord();
 
    }
  
        
    // method called from the VF's action attribute to clone the Payments
    
    public PageReference cloneWithItems() {
     System.debug('Clone method');
     System.debug('old id'+po.id);
              //RETRIEVE the Plot - ONLY INCLUDE THE FIELDS YOU WANT TO RETRIEVE
              
             po = [select id ,Venture__c,plot_status__c ,PLOT__c ,Plot__r.name, CUSTOMER_del__c from Plot__c where id = :po.id];
             
             System.debug('old Customer name'+po.CUSTOMER_del__c);
             System.debug('new Plot Name'+po.PLOT__c);
             
             // set the id of the new po created for testing(u can remove comments subhash)
              // newRecordId = po.plot__c;
               //Kishore code
               newpo = [select id ,Venture__c,plot_status__c ,PLOT__c, CUSTOMER_del__c from Plot__c where id = :po.PLOT__c];
               System.debug('new Customer Name'+newpo.CUSTOMER_del__c);
               //if( newpo.plot_status__c == 'Sold'){
               //return new PageReference('/'+po.PLOT__c );
               //}
                            newpo.plot_status__c = 'Sold';
               newpo.CUSTOMER_del__c = po.CUSTOMER_del__c;
               update newpo;
               //end////////////////
 
             // copy over the Payments - ONLY INCLUDE THE FIELDS YOU WANT TO COPY
             List<payment__c> items = new List<payment__c>();
             for (payment__c pi : [Select p.Id, p.name,p.Payment_Date__c,customer__c,p.Receipt_Number__c,p.Payment_Amount__c,p.Purpose_of_Payment__c,p.Plot__c From payment__c p where plot__c = :po.id]) {
                  if(po.customer_del__c == pi.customer__c){
                  payment__c newPI = pi.clone(false);
                
                 newPI.plot__c = po.PLOT__c ;
                 newPI.customer__c = pi.customer__c;
                 newPI.Payment_Date__c =newpi.Payment_Date__c;
                 newPI.Receipt_Number__c= newpi.Receipt_Number__c;
                 newPI.customer__c=po.CUSTOMER_del__c;
                 
                  items.add(newPI);
                 
                    delete pi;
               }
             }
           
             insert items;

               po.CUSTOMER_del__c = null;
               po.plot_status__c = 'vacant';
               po.PLOT__c = null;
               update po;
              
             return new PageReference('/'+newpo.id+'/e?retURL=%2F'+newpo.id);
            
   
         }
         
         }

the Above one is my class for cloning payments for plots...the below is test case coverage is <60 % please help me to improve th coverage

 

 

@isTest
private class PlotWithrelatedpaymentsControllersuite {
 
    static testMethod void validatePOController() {
 
       // setup a reference to the page the controller is expecting with the parameters
        //PageReference pref = Page.transfer;
       // Test.setCurrentPage(pref);
 
       
 
        // create new po record
        
        customer__c cs =[select id ,name from customer__c LIMIT 1];
        Venture__c v = [Select Name,id From Venture__c LIMIT 1];
          plot__c po = new plot__c();
          po.CUSTOMER_del__c = cs.id ;
        po.venture__c = v.id ;
        po.plot_status__c = 'none';
        po.Mode_of_Sale__c =  'installment';             
        insert po;
        
       
 
        // create a line item for the po
       // Payment__c pi1 = [select id ,name ,Payment_Date__c,Receipt_Number__c from payment__c LIMIT 2];
        payment__c pi1 = new payment__c();
        pi1.Purpose_of_Payment__c = 'Installment';
        pi1.plot__c = po.id;       
        pi1.Payment_Amount__c = 10;
        pi1.Customer__c = po.customer_del__c;
        pi1.Payment_Date__c = Date.newInstance(2020,01,01);
        pi1.Receipt_Number__c ='0000000000';
        insert pi1;
 
        // Construct the standard controller
        ApexPages.StandardController con = new ApexPages.StandardController(po);
 
      
        // Switch to test context
        Test.startTest();
 
        // check that the new po was created successfully
        plot__c newPO = [select id from plot__c where id = :po.id];
        System.assertNotEquals(newPO, null);
        
                
        // check that the line item was created
        List<payment__c> newItems = [Select p.Id From payment__c p where plot__c = :newPO.id];
        System.assertEquals(newItems.size(),1);
        
           List<payment__c> newItems1 = [Select p.customer__c From payment__c p where plot__c = :newPO.id];
        System.assertEquals(newItems.size(),1);
        
         List<payment__c> newItems2 = [Select p.plot__c From payment__c p where plot__c = :newPO.id];
        System.assertEquals(newItems.size(),1);
        
        //venture,plot is inserted or not
 Venture__c ve = [Select Name,id From Venture__c LIMIT 1];
Plot__c p = new Plot__C(name =ve.id ,Plot_Status__c = 'vacant',VENTURE__c=ve.id);
ve.name = p.VENTURE__c;
insert p;

System.assertEquals(p.name, p.VENTURE__c);
        // Switch back to runtime context
        Test.stopTest();
 
    }
 
}

 Any suggestions please

 

 

 

  • October 26, 2010
  • Like
  • 0

hi 

 

How to copy same Opp Line items to New opportunity from Existing Opp,apart from cloning is there any way to do that...

 

  //copy the Plot - ONLY INCLUDE THE FIELDS YOU WANT TO COPY
             po = [select Id, Name,venture__c,Plot__c from Plot__c where id = :po.id];
             newPO = po.clone(false);
             newPO.venture__c = po.Venture__c; 
             newPO.plot__c = po.plot__c;
             insert newPO;
 
             // set the id of the new po created for testing
               newRecordId = newPO.id;
               
 
             // copy over the Payments - ONLY INCLUDE THE FIELDS YOU WANT TO COPY
             List<payment__c> items = new List<payment__c>();
             for (payment__c pi : [Select p.Id, p.name,p.Payment_Date__c,p.Receipt_Number__c,p.Payment_Amount__c,p.Purpose_of_Payment__c From payment__c p where plot__c = :po.id]) {
                  payment__c newPI = pi.clone(false);
                
                 newPI.plot__c = newPO.plot__c ;
                  newPI.Payment_Date__c =newpi.Payment_Date__c;
                  newPI.Receipt_Number__c= newpi.Receipt_Number__c;
                  items.add(newPI);
                  delete pi;
                  
             }
             insert items;
             
 

 

 

here i am using the above functonality to clone to new record,with new id....But i want to select the record from Exixting Data base table of Opprtunities

 

Any ideas!?

 

 

  • October 19, 2010
  • Like
  • 0

Hi

I created a custom text field named Plot S.no ,i created a custom button Transfer ,when clicked opens a VF page with Plot sno,here i wantedplot sno as Look up field....

 

Any ideas please...!?

  • October 18, 2010
  • Like
  • 0

Hi

 

I created a custom text field named Plot S.no ,i created a custom button Transfer ,when clicked opens a VF page with Plot sno,here i wanted plot sno as Look up field....

 

Any ideas please...!?

  • October 18, 2010
  • Like
  • 0

Hi

I created a custom text field named Plot S.no ,i created a custom button Transfer ,when clicked opens a VF page with Plot sno,here i wantedplot sno as Look up field....

 

Any ideas please...!?

  • October 18, 2010
  • Like
  • 0

Hi

 

I created a custom text field named Plot S.no ,i created a custom button Transfer ,when clicked opens a VF page with Plot sno,here i wanted plot sno as Look up field....

 

Any ideas please...!?

  • October 18, 2010
  • Like
  • 0