• kermit.thefrog
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Architect
  • Blue Bricks

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

I have a custom object "Invoices__c" with a button to create a pdf document. This document is a visualforce page rendering as pdf. My issue is that based on a picklist value on my invoice-object I need to create an invoices with different layouts.

I read somewhere a solution for this, but I cannot find it anymore. The idea was to have a visualforce page with an "if-statement" that checks the picklist values and directs to another visualforce page which renders the pdf with the required layout.

Has anyone an idea how the if-statement on a visualforce page that directs to another one should look like?

Many thanks for your help!
I have a flow that helps users to create an opportunity with products. When the flow finishes I want salesforce to generate a quote (consisting of data from Account, Opportunity and OpportunityProducts). This quote is generated as a pdf and I want that this quote is attached as a pdf-file to the opportunity.

I found some useful hints to set this up, but it seems that my testclass is not covering at least 75% (just 5%). Can somebody please look into this a point me into the right direction to get this running?

ApexClass:
 
public class attachPDFToOpportunity {
    
    private final Opportunity a; 
    
    
    public attachPDFToOpportunity(ApexPages.StandardController standardPageController) {
        a = (Opportunity)standardPageController.getRecord(); 
    }
    
    
    public PageReference attachPDF() {
        
        
        PageReference pdfPage = Page.wedoQuote; 
        Blob pdfBlob; 
        if (!Test.isRunningTest()) { 
            pdfBlob = pdfPage.getContent(); 
        } else { 
            pdfBlob = Blob.valueOf('Some Text');
        }
        Attachment attach = new Attachment(parentId = a.Id, Name = 'pdfAttachmentDemo.pdf', body = pdfBlob); 
        insert attach; 
        
        
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); 
        pageWhereWeWantToGo.setRedirect(true); 
        return pageWhereWeWantToGo; 
    }

}
testClass:
@isTest
private class attachPDFToOpportunityTest {
    
    //tests attachPDFToOpportunity
    @isTest //defines method for use during testing only
    static void attachPDFLogic() {
        //BEGIN: Some Setup Items...
        List<Opportunity> opportunities = new List<Opportunity>();
        opportunities.add(new Opportunity(Name = 'TestOppApex', StageName = 'Qualification', CloseDate = date.today()));
        
        insert opportunities;
        //END: Some Setup Items...
        
        Test.startTest(); //denote testing context
        
        PageReference pageRef = Page.attachPDFToOpportunity; //create a page reference to attachPDFToAccount.page
        Test.setCurrentPage(pageRef); //set page context
        ApexPages.StandardController standardController = new ApexPages.standardController(opportunities[0]); //instantiate the standard Account object controller
        attachPDFToOpportunity ext = new attachPDFToOpportunity(standardController); //instantiate the extension
        
        String validationURLString = ext.attachPDF().getURL(); //get the URL that is returned after the attachPDF() method is invoked
        String opportunityIdAsString = Id.valueOf(opportunities[0].Id); //variable represtenting the Account record Id as a String
        System.assertEquals(true, validationURLString.contains(opportunityIdAsString.left(15))); //validate that the URL contains the Id of the Account record
        
        Test.stopTest(); //revert from testing context
    }

}


Many thanks!
I have a flow that helps users to create an opportunity with products. When the flow finishes I want salesforce to generate a quote (consisting of data from Account, Opportunity and OpportunityProducts). This quote is generated as a pdf and I want that this quote is attached as a pdf-file to the opportunity.

I found some useful hints to set this up, but it seems that my testclass is not covering at least 75% (just 5%). Can somebody please look into this a point me into the right direction to get this running?

ApexClass:
 
public class attachPDFToOpportunity {
    
    private final Opportunity a; 
    
    
    public attachPDFToOpportunity(ApexPages.StandardController standardPageController) {
        a = (Opportunity)standardPageController.getRecord(); 
    }
    
    
    public PageReference attachPDF() {
        
        
        PageReference pdfPage = Page.wedoQuote; 
        Blob pdfBlob; 
        if (!Test.isRunningTest()) { 
            pdfBlob = pdfPage.getContent(); 
        } else { 
            pdfBlob = Blob.valueOf('Some Text');
        }
        Attachment attach = new Attachment(parentId = a.Id, Name = 'pdfAttachmentDemo.pdf', body = pdfBlob); 
        insert attach; 
        
        
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); 
        pageWhereWeWantToGo.setRedirect(true); 
        return pageWhereWeWantToGo; 
    }

}
testClass:
@isTest
private class attachPDFToOpportunityTest {
    
    //tests attachPDFToOpportunity
    @isTest //defines method for use during testing only
    static void attachPDFLogic() {
        //BEGIN: Some Setup Items...
        List<Opportunity> opportunities = new List<Opportunity>();
        opportunities.add(new Opportunity(Name = 'TestOppApex', StageName = 'Qualification', CloseDate = date.today()));
        
        insert opportunities;
        //END: Some Setup Items...
        
        Test.startTest(); //denote testing context
        
        PageReference pageRef = Page.attachPDFToOpportunity; //create a page reference to attachPDFToAccount.page
        Test.setCurrentPage(pageRef); //set page context
        ApexPages.StandardController standardController = new ApexPages.standardController(opportunities[0]); //instantiate the standard Account object controller
        attachPDFToOpportunity ext = new attachPDFToOpportunity(standardController); //instantiate the extension
        
        String validationURLString = ext.attachPDF().getURL(); //get the URL that is returned after the attachPDF() method is invoked
        String opportunityIdAsString = Id.valueOf(opportunities[0].Id); //variable represtenting the Account record Id as a String
        System.assertEquals(true, validationURLString.contains(opportunityIdAsString.left(15))); //validate that the URL contains the Id of the Account record
        
        Test.stopTest(); //revert from testing context
    }

}


Many thanks!
I've got an Sobject collection variable in a flow, and I would like to display a list of values from the collection in a display text field.

If I use the varaible resource, it displays the IDs, along the lines of [Id1, Id2, Id3].

Is there any way to get the flow to produce something along the lines of:

Name1, Value1
Name2, Value2,
Name3, Value3,

in a display text field?

If not possible in the flow itself, I'm guessing if I embed the flow in a visualforce page I could pull it off, but would appreciate any tips on going about that.

Thanks

(Cross post from success: https://success.salesforce.com/answers?id=90630000000Cr4J)