1

Can any one help me on this .I have created a custom visual force page on Quote object which is in PDF foramt.I have written a wrapper class where values of the opportunity forecast object gets displayed but not related to the parent record.This "Opportunity Forecast object " is a custom object which is a managed package installation.Is that im making any blunt mistake in the code.Any help is very much appreciated.

For Example :

I have a record created on 12/18/14 on opportunity object with all related list object like quote ,product,competitor etc.When i query on it retrives the all the values of the related record ,but for the "opportunity forecast object" it does not displays the record details created on 12/18/2014 ,but displays some other "record details" which was created on 3/11/2014 with the productid instead of displaying the productname.Is that im querying wrongly .I shall appreciate your help.

Visual Force Code :

<apex:page standardController="Quote" 
        applyHtmlTag="false" renderAs="PDF" showheader="false" applyBodyTag="false" extensions="QuoteContentController">



<h2>OpportunityForecast Details</h2>
 <table class="bordered">
        <thead>
            <tr>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Part Numbers</td>
                <td class="header-table-heading" bgcolor="#C0C0C0">Quantity</td>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Price</td>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Amount</td>
                <td class="header-table-heading" bgcolor="#C0C0C0">Quarter</td>
                <td class="header-table-heading" bgcolor="#C0C0C0">Actual Price</td>
            </tr>
        </thead>
        <tbody>
           <apex:repeat value="{!disp_list}" var="opf">
            <tr>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Product}"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Price }"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Amount }"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Quarter }"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.Actual_Price }"/></td>
             </tr>
            </apex:repeat> 
        </tbody>
    </table> 
</apex:page>

APEX CLASS:

public with sharing class QuoteContentController {

       public Competitor__c com{get;set;}

       public gmod__Opportunity_Forecast__c oppf{get;set;}

       public Id qId {get;set;}

//Declare a wrapper class  

       public class Wrapperclass{

 //custom wrapper datatype  

       Public string Name{get;set;}  
       Public string AccountType{get;set;}  
       Public date todaysDate{get;set;}  
       Public date Expected_Order_Date{get;set;}
       Public string Probability{get;set;}  
       Public string Internal_Comment{get;set;}  
       Public string External_Comment{get;set;}  

       Public string Segment{get;set;}  
       Public string Application{get;set;}  
       Public string Persona{get;set;}  
       Public string Geogrpahy{get;set;}  

       Public string PartNumbers{get;set;}  
       Public Decimal  Price{get;set;}  
       Public Decimal End_Customer_Price{get;set;}  
       Public Decimal Quantity {get;set;}  
       Public Decimal Total{get;set;}  

       Public string RFQ_justification{get;set;}  
       Public string Main_Customer_of_Account{get;set;}  
       Public string Bridgelux_competition_at_account{get;set;}
       Public string Geographic_regions_serviced{get;set;}  
       Public string Annual_lighting_revenue{get;set;}  
       Public string Annual_LED_revenue_or_percent{get;set;}  
       Public string Annual_purchases_of_LED_light_sources{get;set;}
       Public string Percent_of_LED_purchases_that_are_COB{get;set;}  
       Public string Other_information{get;set;}  

       Public string Product_Series{get;set;}  
       Public string Volume{get;set;} 
       Public string Date_Price_is_Valid{get;set;} 

       Public string gmod_Product{get;set;}
       Public Decimal gmod_Quantity{get;set;}
       Public Decimal gmod_Price{get;set;}
       Public Decimal gmod_Quarter{get;set;}
       Public Decimal gmod_Month{get;set;}
       Public Decimal gmod_Amount{get;set;}
       Public Decimal Actual_Price{get;set;}
       Public Decimal  gmod_Year{get;set;}
       Public Date gmod_date{get;set;}

       Public wrapperClass(){} 

  }

       Public QuoteContentController(){}

       Public QuoteContentController(ApexPages.StandardController controller) {

       qId=Apexpages.currentPage().getparameters().get('Id');

    }

       Public List<wrapperClass> disp_list {get;set;}{
    //define constructor to instantiate the wrapper data type 

       disp_list=new list<wrapperclass>();

    //Query all the list 

    list<Quote> q =[select id ,Name ,Effective_Date__c ,Comments__c ,
                    Quote.Opportunity.Probability ,Quote.Opportunity.AccSegment__c ,Quote.Opportunity.AccApplication__c,Quote.Opportunity.Persona__c,Quote.Opportunity.Region__c
                    from Quote where id=:apexpages.currentpage().getparameters().get('id')];

    list<QuoteLineItem> qli =[Select QuoteId , PricebookEntry.Product2.Name ,Unitprice ,End_Customer_Price__c ,Quantity , TotalPrice from QuoteLineItem where QuoteId =:qId ];

    list<Account> a = [Select id ,Name ,Main_Customers_of_Account__c ,Bridgelux_Competition_at_Account__c,Servicing_Region__c ,
                      Annual_LED_Revenue__c,Annual_Purchases_of_LED_Sources_SAM__c ,Percent_of_LED_purchases_that_are_COB__c from Account where account.id =:qId ];

   list<Competitor__c>  com = [Select id ,Part_Number__c,Product_Series__c,Price_Offered__c,Volume__c,Date_Price_is_Valid__c from Competitor__c ]  ; 

   //list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__c,gmod__Quantity__c,gmod__Price__c ,   gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c,gmod__Year__c , gmod__Month__c, gmod__date__c from gmod__Opportunity_Forecast__c   ];

    list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__c,gmod__Quantity__c,gmod__Price__c , gmod__Month__c,    gmod__date__c,  gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c ,gmod__Year__c from gmod__Opportunity_Forecast__c  where createddate!=null order by name limit 1 ]; 

       //Iterate through each list to extract the values and add it to the custom wrapper data type  

         for (Quote qt :q){

            for(integer i=0;i<opflist.size();i++){

                //Instantiating the wrapper SObject 

                wrapperclass w = new wrapperclass();

  //Assigning the wrapper variables from the SObject Fields in the database. 

  w.gmod_Product = opflist[i].gmod__Product__c;

  w.gmod_Quantity =opflist[i].gmod__Quantity__c;

  w.gmod_Price=opflist[i].gmod__Price__c;

  w.Name =opflist[i].Name;

  w.gmod_Quarter=opflist[i].gmod__Quarter__c;

  w.gmod_Month=opflist[i].gmod__Month__c;

  w.gmod_Amount=opflist[i]. gmod__Amount__c;

  w.Actual_Price=opflist[i].Actual_Price__c;

  w.gmod_Year=opflist[i].gmod__Year__c;

  w.gmod_date=opflist[i].gmod__date__c;

      //Adding everthing to the List  


     w.name =qt.name;

      disp_list.add(w);


       }
     }
   }  
 } //End of Class
2
  • We need more information. What records have you already created? What is the parameters passed into the page? Have you tried debugging anywhere to find out what sections of code is firing or not?
    – dphil
    Commented Jan 21, 2015 at 15:31
  • @dphil:On Quote object i have created a formula field for the Vf page .When we create the a record in quote object and save.Once the record is saved.When user clicks the link,the vf page gets opened in the PDF format with record details .
    – nikkey
    Commented Jan 21, 2015 at 15:42

1 Answer 1

3

You have a large number of issues with this page, but I believe I see your main issue. You are grabbing the first gmod__Opportunity_Forecast__c that your query brings up whether it is related to the quote or not. You likely need to add something like AND Quote__c = :cIid

list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__c,gmod__Quantity__c,gmod__Price__c , gmod__Month__c,    gmod__date__c,  gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c ,gmod__Year__c from gmod__Opportunity_Forecast__c  where createddate!=null order by name limit 1 ]; 

You are declaring this variable but then you have a section of blocked code after.

Public List<wrapperClass> disp_list {get;set;}

This section of blocked code is not a method or anything. It's just a block. Right after this variable is:

{
    //define constructor to instantiate the wrapper data type 

   disp_list=new list<wrapperclass>();

//Query all the list 

list<Quote> q =[select id ,Name ,Effective_Date__c ,Comments__c ,
                Quote.Opportunity.Probability ,Quote.Opportunity.AccSegment__c ,Quote.Opportunity.AccApplication__c,Quote.Opportunity.Persona__c,Quote.Opportunity.Region__c
                from Quote where id=:apexpages.currentpage().getparameters().get('id')];

Your code here continues on I understand but it's not really part of a method or anything.

The block itself should be less complex. You should be setting your quote in your constructor and if you have an Id it should only be returning 1 record. That way you can eliminate your loop. In addition, you code appears to be querying for a single opportunity_Forecast__c whether it is related to your quote or not.

list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__c,gmod__Quantity__c,gmod__Price__c , gmod__Month__c,    gmod__date__c,  gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c ,gmod__Year__c from gmod__Opportunity_Forecast__c  where createddate!=null order by name limit 1 ]; 

   //Iterate through each list to extract the values and add it to the custom wrapper data type  

     for (Quote qt :q){

        for(integer i=0;i<opflist.size();i++){

From what I can see, your code doesn't need a wrapper class at all, unless you are planning on adding some additional functionality later on. You can easily just have a list of gmod__Opportunity_Forecast__c and then display them directly on the page.

It might be a good idea for you to learn the basics of a controller extension and keeping your code as simple as possible while you are still learning to code: http://www.salesforce.com/docs/developer/pages/Content/pages_controller_extension.htm

Just to clarify, the main thing I noticed might not be your issue. The formatting of your code though makes it extremely difficult to read. Also, the inefficiencies to as well. These things add up making it increasingly difficult to see what the real issue is. I know this is a lot of criticism on your code, but I'm just trying to help you learn. Good luck!

10
  • :Thanks for your reply.This gmod__Opportunity_Forecast__c object is not related to Quote object.It is an managed packaged installation.It has a Visual page created on Opportunity object related to products and displays the product details in VF page in opportunity detail page.As per Scenario this product details displayed on vf page should get displayed on vF page created Quote Object which is in a PDF format .
    – nikkey
    Commented Jan 21, 2015 at 16:45
  • @nikkey If it's not related in any way, then how can there be any correct child records to bring back?
    – dphil
    Commented Jan 21, 2015 at 16:50
  • :The opportunity has a related list product ,the same product details gets displayed in opportunity Vf page for gmod__Opportunity_Forecast__c with monthly based .In my custom Vf page related to Quote i have opportunity being queried.I get the Opportunity details but the gmod__Opportunity_Forecast__c deatils get varied.
    – nikkey
    Commented Jan 21, 2015 at 17:18
  • @nikkey You aren't using the Opportunity info anywhere and aren't using it to relate to the gmode_Opportunity_Forecast__c as well.
    – dphil
    Commented Jan 21, 2015 at 18:01
  • :Im querying them in Quote list as Quote.Opportunity.Probability ,Quote.Opportunity.AccSegment__c etc.
    – nikkey
    Commented Jan 21, 2015 at 18:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .