• laurent.greiwelding1.3974669707216677E12
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
I have this class :
public with sharing class PdfGeneratorController {

    public PdfGeneratorController(ApexPages.StandardController controller) {

    }


  public ID parentId {get;set;}
  public String pdfName {get;set;}
  public ID factureId {get;set;}

  public PageReference savePdf() {
  
  Facture__c f = [Select Devis__c, Name From Facture__c Where Id = :ApexPages.currentPage().getParameters().get('id')];
  
  factureId = ApexPages.currentPage().getParameters().get('id');
  pdfName = 'Facture '+f.Name;
  parentId = f.Devis__c;

    PageReference pdf = Page.Facture_Puerto_cacao_pdf;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',parentId);

    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = pdfName;
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = factureId;
    insert attach;

    // send the user to the account to view results
    return new PageReference('/'+factureId);

  }

}

and th test class :
@isTest
private class Test_PdfGeneratorController {

  static Facture__c fact;

  static {

    fact = new Facture__c();
    fact.Devis__c = '0Q0L0000000AH4m';
    insert fact;

  }

  static testMethod void testPdfGenerator() {

    PageReference pref = Page.Facture_Puerto_cacao_pdf;
    pref.getParameters().put('id',fact.Devis__c);
    Test.setCurrentPage(pref);
    
    // Instantiate standard Controller
        ApexPages.standardController controller = new ApexPages.standardController(fact);

    // Instantiate controller extension
      PdfGeneratorController con = new PdfGeneratorController(controller);


    Test.startTest();

    // populate the field with values
    con.parentId = fact.Id;
    con.pdfName = 'My Test PDF';

    // submit the record
    pref = con.savePdf();

    // assert that they were sent to the correct page
    System.assertEquals(pref.getUrl(),'/'+fact.id);

    // assert that an attachment exists for the record
    System.assertEquals(1,[select count() from attachment where parentId = :fact.Devis__c]);

    Test.stopTest(); 

  }
}

The code coverage is 26%, can you help me please 
Hy evrybody,

Can you help me for make the test for this class :

public with sharing class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
        this.controller = controller;
    }

    public PageReference getRedir() {

        PageReference newPage;
        
         String c = ApexPages.currentPage().getParameters().get('RecordType');
         String a = ApexPages.currentPage().getParameters().get('accid');
                   
        if (C == '012F0000000yGsq') {
            newPage = Page.Visual_contact;
            newPage.getParameters().put('RecordType', c);          
            newPage.getParameters().put('accid', a);
           
            return newPage.setRedirect(true);           
                   
        } else {
           
            newPage = new PageReference('/003/e');
            newPage.getParameters().put('accid', a);
            newPage.getParameters().put('RecordType', c);
            newPage.getParameters().put('nooverride', '1');
            return newPage.setRedirect(true);
        }

   
   
    }

    public final ApexPages.StandardController controller;
   
   

}

I'm lost with the test
Hy evrybody,

Can you help me for make the test for this class :

public with sharing class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
        this.controller = controller;
    }

    public PageReference getRedir() {

        PageReference newPage;
        
         String c = ApexPages.currentPage().getParameters().get('RecordType');
         String a = ApexPages.currentPage().getParameters().get('accid');
                   
        if (C == '012F0000000yGsq') {
            newPage = Page.Visual_contact;
            newPage.getParameters().put('RecordType', c);          
            newPage.getParameters().put('accid', a);
           
            return newPage.setRedirect(true);           
                   
        } else {
           
            newPage = new PageReference('/003/e');
            newPage.getParameters().put('accid', a);
            newPage.getParameters().put('RecordType', c);
            newPage.getParameters().put('nooverride', '1');
            return newPage.setRedirect(true);
        }

   
   
    }

    public final ApexPages.StandardController controller;
   
   

}

I'm lost with the test
I have this class :
public with sharing class PdfGeneratorController {

    public PdfGeneratorController(ApexPages.StandardController controller) {

    }


  public ID parentId {get;set;}
  public String pdfName {get;set;}
  public ID factureId {get;set;}

  public PageReference savePdf() {
  
  Facture__c f = [Select Devis__c, Name From Facture__c Where Id = :ApexPages.currentPage().getParameters().get('id')];
  
  factureId = ApexPages.currentPage().getParameters().get('id');
  pdfName = 'Facture '+f.Name;
  parentId = f.Devis__c;

    PageReference pdf = Page.Facture_Puerto_cacao_pdf;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',parentId);

    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = pdfName;
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = factureId;
    insert attach;

    // send the user to the account to view results
    return new PageReference('/'+factureId);

  }

}

and th test class :
@isTest
private class Test_PdfGeneratorController {

  static Facture__c fact;

  static {

    fact = new Facture__c();
    fact.Devis__c = '0Q0L0000000AH4m';
    insert fact;

  }

  static testMethod void testPdfGenerator() {

    PageReference pref = Page.Facture_Puerto_cacao_pdf;
    pref.getParameters().put('id',fact.Devis__c);
    Test.setCurrentPage(pref);
    
    // Instantiate standard Controller
        ApexPages.standardController controller = new ApexPages.standardController(fact);

    // Instantiate controller extension
      PdfGeneratorController con = new PdfGeneratorController(controller);


    Test.startTest();

    // populate the field with values
    con.parentId = fact.Id;
    con.pdfName = 'My Test PDF';

    // submit the record
    pref = con.savePdf();

    // assert that they were sent to the correct page
    System.assertEquals(pref.getUrl(),'/'+fact.id);

    // assert that an attachment exists for the record
    System.assertEquals(1,[select count() from attachment where parentId = :fact.Devis__c]);

    Test.stopTest(); 

  }
}

The code coverage is 26%, can you help me please 
Hy evrybody,

Can you help me for make the test for this class :

public with sharing class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
        this.controller = controller;
    }

    public PageReference getRedir() {

        PageReference newPage;
        
         String c = ApexPages.currentPage().getParameters().get('RecordType');
         String a = ApexPages.currentPage().getParameters().get('accid');
                   
        if (C == '012F0000000yGsq') {
            newPage = Page.Visual_contact;
            newPage.getParameters().put('RecordType', c);          
            newPage.getParameters().put('accid', a);
           
            return newPage.setRedirect(true);           
                   
        } else {
           
            newPage = new PageReference('/003/e');
            newPage.getParameters().put('accid', a);
            newPage.getParameters().put('RecordType', c);
            newPage.getParameters().put('nooverride', '1');
            return newPage.setRedirect(true);
        }

   
   
    }

    public final ApexPages.StandardController controller;
   
   

}

I'm lost with the test