• James Hoyles 10
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I have a wrapper class that I can't seem to get more than 20% coverage on, can someone help? Here is the controller code:

public class Add_QLI {
    public String opportunitystringId {get;set;}
    public List<Opportunity> opportunityList {get;set;}
    public List<quotewrapper> quotewrapperlist {get;set;}
    public List<OpportunityLineItem> oliList{get;set;}
    public Opportunity CurrentOpp{get;set;}
    public Opportunity SourceOpp{get;set;}
    
    public class quotewrapper
    {
        public Boolean isChecked {get;set;}
        public OpportunityLineItem oliresult {get;set;}
        
        public quotewrapper(Boolean isChecked, OpportunityLineItem oliresult)
        {
            This.isChecked = isChecked;
            This.oliresult = oliresult;
        } 
    }   
    
    public Add_QLI(ApexPages.StandardController controller)
    {CurrentOpp = (Opportunity)controller.getRecord();
     SourceOpp = [SELECT id,Percentage_Uplift__c FROM Opportunity WHERE id = :CurrentOpp.id];
        try{
            quotewrapperlist = new List<quotewrapper>();
            opportunitystringId  = ApexPages.CurrentPage().getparameters().get('Id');
            
            if(opportunitystringId!=null)
            {
                opportunityList = [SELECT Id,Name,CloseDate,AccountId,Pricebook2Id from Opportunity WHERE Id =:opportunitystringId];
                oliList = [Select Id,Name,Quantity,OpportunityId,UnitPrice,Product2Id,PricebookentryId,TotalPrice,Height_M__c,Length_M__c,Hire_in_Weeks__c,Extra_weeks_after_initial_20_weeks__c from OpportunityLineItem WHERE OpportunityId =:opportunitystringId order by Name];
            }
            
            if(oliList.size()>0)
            {
                for(OpportunityLineItem olObj:oliList)
                {
                    quotewrapper qobj =  new quotewrapper(false, olObj);
                    quotewrapperlist.add(qobj);
                }
            }
        }
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }       
    }
    
    public pagereference saveQuote()
    {
        try{
            List<OpportunityLineItem> olilistNew = new List<OpportunityLineItem>();  
            List<QuoteLineItem>  quoteItemList = new List<QuoteLineItem>();
            
            for(quotewrapper qwr : quotewrapperlist)
            {
                if(qwr.isChecked==true)
                {
                    olilistNew.add(qwr.oliresult);
                }
            }
            
            List<Quote> quoteListNew = new List<Quote>();
            if(opportunityList.size()>0)
            {
                for(Opportunity opportunityObj : opportunityList)
                {
                    Quote quoteObj = new Quote();
                    quoteObj.Name=datetime.now()+opportunityObj.Name;
                    quoteObj.OpportunityId = opportunityObj.Id;
                    quoteObj.Pricebook2Id =opportunityObj.Pricebook2Id;
                    quoteObj.Percentage_Uplift__c =SourceOpp.Percentage_Uplift__c;
                    quoteListNew.add(quoteObj); 
                }
            }
            if(quoteListNew.size()>0)
            {
                Database.SaveResult[] quoteItemSaveList = Database.insert(quoteListNew);
            }
            if(olilistNew.size()>0)
            {
                for(Quote qutObj: quoteListNew)
                { 
                    for(OpportunityLineItem oliObj : olilistNew)
                    {  
                        QuoteLineItem qlobj = new QuoteLineItem();
                        qlobj.Quantity=oliObj.Quantity;
                        qlobj.PricebookEntryId=oliObj.PricebookEntryId;
                        qlobj.QuoteId=qutObj.Id;
                        qlobj.Product2Id=oliObj.Product2Id;
                        qlobj.UnitPrice=oliObj.UnitPrice;
                        qlobj.Height_M__c=oliObj.Height_M__c;
                        qlobj.Length_M__c=oliObj.Length_M__c;
                        qlobj.Hire_in_Weeks__c=oliObj.Hire_in_Weeks__c;
                        qlobj.Extra_weeks_after_initial_20_weeks__c=oliObj.Extra_weeks_after_initial_20_weeks__c;
                        quoteItemList.add(qlobj);   
                    }
                }
                if(quoteItemList.size()>0)
                {
                    Database.SaveResult[] quoteItemSaveList = Database.insert(quoteItemList);
                }
            } 
        } 
        
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(CurrentOpp).view(); //we want to redirect the User back to the Account detail page
        pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
        return pageWhereWeWantToGo; //send the User on their way
    }
}
Hi All,
I'm trying to have both portrait (page one) and landscape (page two) in a visualforce page which is 'render as PDF'.
I have tried various options but cannot get it to work, I can only get all landscape or all portrait, here is the code, please help!

<apex:page Controller="RAMS_Controller" showHeader="false" renderas="pdf" applyBodyTag="false" applyHtmlTag="false">
       <html>
        <head>
            <style>
                @page{
                    size: A4 landscape;
                }
            </style>
<!-- Page 1 -->
<div style="text-align:center;">
        <p style="text-align:center;font-size: 25px"><font face="Arial">Page One</font></p>
</div>
<!-- Page 2 -->    
<div style="text-align:center;">
    
        <p style="text-align:center;font-size: 25px"><font face="Arial">Page Two</font></p>
</div>
           </head>
    </html>
I have a wrapper class that I can't seem to get more than 20% coverage on, can someone help? Here is the controller code:

public class Add_QLI {
    public String opportunitystringId {get;set;}
    public List<Opportunity> opportunityList {get;set;}
    public List<quotewrapper> quotewrapperlist {get;set;}
    public List<OpportunityLineItem> oliList{get;set;}
    public Opportunity CurrentOpp{get;set;}
    public Opportunity SourceOpp{get;set;}
    
    public class quotewrapper
    {
        public Boolean isChecked {get;set;}
        public OpportunityLineItem oliresult {get;set;}
        
        public quotewrapper(Boolean isChecked, OpportunityLineItem oliresult)
        {
            This.isChecked = isChecked;
            This.oliresult = oliresult;
        } 
    }   
    
    public Add_QLI(ApexPages.StandardController controller)
    {CurrentOpp = (Opportunity)controller.getRecord();
     SourceOpp = [SELECT id,Percentage_Uplift__c FROM Opportunity WHERE id = :CurrentOpp.id];
        try{
            quotewrapperlist = new List<quotewrapper>();
            opportunitystringId  = ApexPages.CurrentPage().getparameters().get('Id');
            
            if(opportunitystringId!=null)
            {
                opportunityList = [SELECT Id,Name,CloseDate,AccountId,Pricebook2Id from Opportunity WHERE Id =:opportunitystringId];
                oliList = [Select Id,Name,Quantity,OpportunityId,UnitPrice,Product2Id,PricebookentryId,TotalPrice,Height_M__c,Length_M__c,Hire_in_Weeks__c,Extra_weeks_after_initial_20_weeks__c from OpportunityLineItem WHERE OpportunityId =:opportunitystringId order by Name];
            }
            
            if(oliList.size()>0)
            {
                for(OpportunityLineItem olObj:oliList)
                {
                    quotewrapper qobj =  new quotewrapper(false, olObj);
                    quotewrapperlist.add(qobj);
                }
            }
        }
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }       
    }
    
    public pagereference saveQuote()
    {
        try{
            List<OpportunityLineItem> olilistNew = new List<OpportunityLineItem>();  
            List<QuoteLineItem>  quoteItemList = new List<QuoteLineItem>();
            
            for(quotewrapper qwr : quotewrapperlist)
            {
                if(qwr.isChecked==true)
                {
                    olilistNew.add(qwr.oliresult);
                }
            }
            
            List<Quote> quoteListNew = new List<Quote>();
            if(opportunityList.size()>0)
            {
                for(Opportunity opportunityObj : opportunityList)
                {
                    Quote quoteObj = new Quote();
                    quoteObj.Name=datetime.now()+opportunityObj.Name;
                    quoteObj.OpportunityId = opportunityObj.Id;
                    quoteObj.Pricebook2Id =opportunityObj.Pricebook2Id;
                    quoteObj.Percentage_Uplift__c =SourceOpp.Percentage_Uplift__c;
                    quoteListNew.add(quoteObj); 
                }
            }
            if(quoteListNew.size()>0)
            {
                Database.SaveResult[] quoteItemSaveList = Database.insert(quoteListNew);
            }
            if(olilistNew.size()>0)
            {
                for(Quote qutObj: quoteListNew)
                { 
                    for(OpportunityLineItem oliObj : olilistNew)
                    {  
                        QuoteLineItem qlobj = new QuoteLineItem();
                        qlobj.Quantity=oliObj.Quantity;
                        qlobj.PricebookEntryId=oliObj.PricebookEntryId;
                        qlobj.QuoteId=qutObj.Id;
                        qlobj.Product2Id=oliObj.Product2Id;
                        qlobj.UnitPrice=oliObj.UnitPrice;
                        qlobj.Height_M__c=oliObj.Height_M__c;
                        qlobj.Length_M__c=oliObj.Length_M__c;
                        qlobj.Hire_in_Weeks__c=oliObj.Hire_in_Weeks__c;
                        qlobj.Extra_weeks_after_initial_20_weeks__c=oliObj.Extra_weeks_after_initial_20_weeks__c;
                        quoteItemList.add(qlobj);   
                    }
                }
                if(quoteItemList.size()>0)
                {
                    Database.SaveResult[] quoteItemSaveList = Database.insert(quoteItemList);
                }
            } 
        } 
        
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(CurrentOpp).view(); //we want to redirect the User back to the Account detail page
        pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
        return pageWhereWeWantToGo; //send the User on their way
    }
}

Hi, On Quote Line Items related list I have created a custom button. This custom button will create a visualforce page which will be rendered as pdf.

My issue is that if on the Quote Line Item related list I select more than one Quote Line Item, then all the selected Quote Line Items must be included in the pdf. I am a beginner as developer. So any help to get this done will be highly appreciated.

Also I followed few steps mentioned in this post - https://developer.salesforce.com/forums/?id=906F000000091nOIAQ, however I do not know how to return the selected ids back to vf page and how to make use of them in the vf page.

Please can someone help me with this.

Thank you in advance.

Regards,

Shalini.