function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nikkeynikkey 

Apex Code Logic written to change the value in visualforce page doesnot work


Can any one help me on this? I have a Visualforce page created on Opportunity object which is in PDF format. I have a few RollUp summary fields created on opportunity object. There is a Wrapper class written on Opportunity Product. Now I would like to call these RollUp summary fields in the wrapper class based on a Condition. How do I wrap the RollUp summary field in a class? Any help very much appreciated.

Subtotal__c and Non_Pick_Total__c are Roll up summary fields on Opportunity Object. They give the "Sum" of Opportunity Product aggregates on Extension Field.

Extension(Extension=qty*1) is a Formula field data type as Currency on Opportunity Product.

The issue I'm having is that the "Extension" field value is getting calculated based on the formula field but it should get calculated as per the changes made in the VisualForce page and display (Extension = Qty*0.01) on the subtotal.
 
for (integer i=0; i < OPplineitem.size(); i++) {
    tempObj = new wrapperClass();
    tempObj.productname= OPplineitem[i].PricebookEntry.Product2.Name;
    tempObj.BinItemCode=OPplineitem[i].Bin_Item_Code__c;
    tempObj.quantity=OPplineitem[i].Quantity;
    tempObj.totalamount=OPplineitem[i].Sys_total_Amount__c;
    // tempObj.Subtotal =OPplineitem[i].Opportunity.Subtotal__c;
    //   tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c;
    //Add a conditional statement here
    if (OPplineitem[i].PricebookEntry.Product2.Product_Line__c=='DIE') {
        tempObj.unitprice=0.01;
        tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice;
        tempObj.productname=OPplineitem[i].Bin_Item_Code__c;

        if (i==0) {
            tempObj2.Subtotal=tempobj.extension;
            system.debug('@@@@@@@@'+tempObj2.Subtotal);
        } else {
            tempObj2.Subtotal=tempObj2.Subtotal+tempObj.extension;
        }
    } else {
        tempObj.unitprice=1;
        //tempObj.unitprice=OPplineitem[i].ListPrice;
        tempobj.extension=OPplineitem[i].Extension__c ;
    }
}

When i check in the Debug logs the value gets calculated but it does not get changed in the visual force page.Any help very much appreciated.
ShotShot
could you show please VF page also?
nikkeynikkey
Hi Bogdan Kulyk,
VF CODE :
<apex:page standardController="Opportunity"  renderAs="PDF" applyhtmltag="false" showHeader="false" applyBodyTag="false" extensions="InvoiceController">

 
     <table border="0" cellspacing="0" cellpadding="1" width="100%" >
        <tr>
            <td class="header-heading">
                Ship Date:
            </td>
            <td class="header-data">
                <apex:outputText value="{!opportunity.Sys_today_s_date__c}"></apex:outputText><br/>
            </td>
            <td class="header-heading">
                Special Instructions:
            </td>
            <td class="header-data">                
                <apex:outputText value="{!opportunity.Special_Instructions__c}"></apex:outputText>
            </td>
        </tr>
        <tr>
            <td><b><f style="color:Black; font-size:14px; font-family:Verdana;"></f></b> &nbsp;&nbsp;<apex:outputText value="{!Opportunity.Customer_VAT_number__c}"></apex:outputText><br/>
            </td>
        </tr>
    </table> 
 
    <table>
        <tr border="0">
            <td class="header-table-heading">CI Invoice Id</td>
            <td class="header-table-heading">Ship Date<b/></td>
            <!--<td class="header-table-heading">Sales Order#</td>-->
            <td class="header-table-heading">Opportunity Name</td>
            <td class="header-table-heading">Order Date</td>
            <!--<td class="header-table-heading">Customer#</td>-->
            <td class="header-table-heading">Customer Name</td>
        </tr>
        <tr>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Salesorder_number__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.Sys_today_s_date__c}"></apex:outputText></td>
            <!--<td class="header-table-data"><apex:outputText value="{!Opportunity.Salesorder_number__c}"></apex:outputText></td>-->
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Name}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Sys_createddate__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.account.Name}"></apex:outputText></td>
            <!--<td class="header-table-data">{!Opportunity.account.Ebs_Customer_number__c}</td>-->
        </tr>
    </table>
    <br/>
    <table >
        <tr>
            <td class="header-table-heading">LN</td>
            <td class="header-table-heading">Item</td>
            <!--<td class="header-table-heading">BinItemCode</td>-->
            <td class="header-table-heading">Customer Item #<b/></td>
            <td class="header-table-heading">COO</td>
            <td class="header-table-heading">ECCN #</td>
            <td class="header-table-heading">UOM</td>
            <td class="header-table-heading">Unit Price</td>
            <td class="header-table-heading">Quantity</td>
            <td class="header-table-heading">Extension</td>
        </tr>
        <tr>
            <td class="header-table-heading"></td>
            <td colspan="8" style="text-align:left"  class="header-table-heading">Description</td>
        </tr>
        <apex:repeat value="{!appointmentList}" var="line">
        <apex:outputPanel layout="none" rendered="{!if(line.pick==false, true, false)}">

        <tr>         
            <td class="header-table-data"><apex:outputText value="{!line.LineNumber}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!line.productname}"></apex:outputText></td>
            <!--<td class="header-table-data"><apex:outputText value="{!line.BinItemCode}"></apex:outputText></td>-->
            <td class="header-table-data"></td>
            <td class="header-table-data"></td>
            <td class="header-table-data">8541.40.2000</td>
            <td class="header-table-data">EA</td>
            <!--<td class="header-table-data">$1</td>-->
            <td class="header-table-data">$<apex:outputtext value="{!line.unitprice}"></apex:outputtext></td>
            <td class="header-table-data"><apex:outputtext value="{!line.quantity}"></apex:outputtext></td>
            <td class="header-table-data"><apex:outputtext value="{!line.extension}"></apex:outputtext></td>
        </tr>
        <tr>
            <td class="header-table-data"></td>
            <td colspan="8" style="text-align:left" class="header-table-data"><b>Scheduled Ship Date:</b>
                        <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                                <apex:param value="{!line.Scheduledshipdate}"/>
                        </apex:outputText> </td>
        </tr>
        </apex:outputPanel>    
        </apex:repeat>
    </table>
    <br/>
    <table>
        <tr>
            <td class="header-table-heading">Gross Weight</td>
            <td class="header-table-heading">Net Weight</td>
            <td class="header-table-heading">Shipped Via</td>
            <td class="header-table-heading">Tracking #</td>
            <td class="header-table-heading">Payment Terms</td>
            <td class="header-table-heading">Incoterms </td>
            <td class="header-table-heading">Currency </td>
            <td rowspan="0" class="header-table-heading">Sub Total <br/>Shipping Charges</td>
            <td rowspan="0" class="header-table-data" id="sub"><apex:outputText value="{!opportunity.Non_Pick_Total__c}"></apex:outputText>
       <br/><apex:outputText value="{!Opportunity.Shipping_Charges__c}"></apex:outputText><br/></td>

        </tr>
        <apex:repeat value="{!appointmentList1}" var="line1">
        </apex:repeat>
        <tr>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Gross_Weight__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Net_weight__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Shipped_Via__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Bill_of_Lading__c}"> </apex:outputText></td>
            <td class="header-table-data">Net 30</td>
            <td class="header-table-data">EXW</td>
            <td class="header-table-data">USD</td>
            <td rowspan="0" class="header-table-heading"> Total Amount Due</td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.Non_Pick_Total__c + opportunity.Shipping_Charges__c}"></apex:outputText></td>
        </tr>
    </table>
</body>
</apex:page>

PFA SCREEN SHOT :ScreenShot

Any help very much appreciated.
ShotShot
Here are fields which have wrong data:
<apex:outputText value="{!opportunity.Non_Pick_Total__c}"></apex:outputText>
  
<apex:outputText value="{!Opportunity.Shipping_Charges__c}"></apex:outputText>
</td>
And here:
<td class="header-table-data"><apex:outputText value="{!opportunity.Non_Pick_Total__c + opportunity.Shipping_Charges__c}"></apex:outputText></td>
These fields of standard controller, not a wrapper class.


 
nikkeynikkey
Hi Bogdan Kulyk,
Subtotal__c and Non_Pick_Total__c are Roll up summary fields on Opportunity Object. They give the "Sum" of Opportunity Product aggregates on Extension Field.
Non_Pick_Total__c --Data Type Roll-Up Summary Summary Type SUM
                              Summarized Object Opportunity Product    
                            Field to Aggregate Opportunity Product: Extension
                          Filter Criteria PickEQUALSFalse

Similarly for Pick Total :Data Type Roll-Up Summary Summary Type SUM
                                 Summarized Object Opportunity Product    
                                   Field to Aggregate Opportunity Product: Extension
                                  Filter Criteria PickEQUALS TRUE
Subtotal :Data Type Roll-Up Summary Summary Type SUM
               Summarized Object Opportunity Product    
                Field to Aggregate Opportunity Product: Extension
                Filter Criteria

Controller :
public with sharing class InvoiceController {
           List<wrapperClass> appointmentList {get;set;}
           List<wrapperClass> appointmentList1 {get;set;} 
           public list<string> address{get;set;}
           public string address1{get;set;}
           public string address2{get;set;}
           public string address3{get;set;}
           public string address4{get;set;}
           public string address5{get;set;}
           public string address6{get;set;}
           public string address7{get;set;}
           public String showaddressonVf{get;set;}
           public string wholeaddress{get;set;}
            public static wrapperClass tempObj2 ;

   //Added by sumit
               List<String> stringList ;
               public String all{get;set;}
           //------------
   public InvoiceController(){
   list<opportunity> op=[select id,Shipment_Info__c
   from opportunity where id=:apexpages.currentpage().getparameters().get('id')];
    //opportunity op=[select id,Shipment_Info__c from opportunity where id=:apexpages.currentpage().getparameters().get('id')];
       //---------------------Added by sumit----------------------
       stringList= new List<String>(); 
       if(op.size()>0)
       if(op[0].Shipment_Info__c!=NULL && op[0].Shipment_Info__c!=''){
           List<String> stringList=(op[0].Shipment_Info__c).split(',');
               for(integer i=0;i<stringList.size();i++){
                   all=all+stringList[i]+'<br/>';
               }
           
           all=all.remove('null');      
        }
      //------------------------------------------------------------
   }
       public Id OppId{get;set;}
   
       
    
       public InvoiceController(ApexPages.StandardController sc) {
       oppId=Apexpages.currentPage().getparameters().get('Id');
   }
               public List<wrapperClass> getappointmentList (){
               wrapperClass tempObj;
               tempObj = new wrapperClass();
        
               List<wrapperClass> aReList = new List<wrapperClass>(); 
           List<Opportunity> opp=[select id,Name,AccountId from Opportunity where id=:oppid limit 1];
           List<opportunity> Opp1=[select id,name,CreatedDate from opportunity where id=:oppid];
           //Opportunity opp1=[select id,Name,AccountId from Opportunity where id=:oppid limit 1];
           //Opportunity Opp=[select id,name,CreatedDate from opportunity where id=:oppid ];
                          List<OpportunityLineItem> OPplineitem= [SELECT OpportunityId,Quantity,PricebookEntry.Product2.Name,Sys_total_Amount__c,LN__c,Extension__c,ListPrice
                          ,Pick__c,Schedule_Ship_date__c,Bin_Item_Code__c ,PricebookEntry.Product2.Product_Line__c,OpportunityLineItem.Opportunity.Subtotal__c,OpportunityLineItem.Opportunity.Non_Pick_Total__c
                           FROM OpportunityLineItem where OpportunityId=:oppId]; 
                          system.debug('HHHHHHHHHH'+OPplineitem.size());
                          tempObj2 =new wrapperClass();
                         // tempObj1.Subtotal=
                       for(integer i=0; i < OPplineitem.size(); i++)
                       {
                     tempObj = new wrapperClass();
                     tempObj.productname= OPplineitem[i].PricebookEntry.Product2.Name;
                     tempObj.BinItemCode=OPplineitem[i].Bin_Item_Code__c;
                     tempObj.quantity=OPplineitem[i].Quantity;
                     tempObj.totalamount=OPplineitem[i].Sys_total_Amount__c;
                    // tempObj.Subtotal =OPplineitem[i].Opportunity.Subtotal__c;
                 //   tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c;

                     //j=j+OPplineitem[i].Quantity * tempObj.unitprice;

                    // tempObj.productline=OPplineitem[i].PricebookEntry.Product2.Product_Line__c;
                     //Add a conditional statement here
                
                
                 if(OPplineitem[i].PricebookEntry.Product2.Product_Line__c=='DIE') 
                     {
                      tempObj.unitprice=0.01;
                      tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice;
                      tempObj.productname=OPplineitem[i].Bin_Item_Code__c;
                      //tempObj.Subtotal =j;
                      if(i==0){
                      tempObj2.Subtotal=tempobj.extension;
                     }
                     else{
                      tempObj2.Subtotal=tempObj2.Subtotal+tempObj.extension;
                       }
                    
                    // tempObj1.Subtotal =tempObj1.Subtotal+tempObj.extension;
                     system.debug('@@@@@@@@'+tempObj2.Subtotal);

                    //tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c*tempObj.unitprice;
                      
                     }
                 else
                     {
                     tempObj.unitprice=1;
                     //tempObj.unitprice=OPplineitem[i].ListPrice;
                     tempobj.extension=OPplineitem[i].Extension__c ;
                    }
                     tempobj.LineNumber=OPplineitem[i].LN__c;
                     tempobj.Pick= OPplineitem[i].Pick__c;
                     tempobj.ScheduledShipDate = Opplineitem[i].schedule_ship_date__c;
                     
                     if(tempobj!=null){
                        aReList.add(tempObj);
                     }
                    }
                   
           return aReList;
           
           
   }
   
   
  
       public List<wrapperClass> getappointmentList1 (){
           wrapperClass tempObj1 ; 
           List<wrapperClass> aReList1 = new List<wrapperClass>();
                   List<Opportunity> opp=[select id,Name,AccountId,Shipment_Info__c,
                    Shipping_Address_Line1__c,
                        Shipping_Address_Line2__c,
                        Shipping_Address_Line3__c,
                        Shipping_City__c,
                        Shipping_State_Province__c,
                        Shipping_Zipcode__c,
                        Shipping_Country__c  
                        from Opportunity where id=:oppid];
           for(integer i=0; i < opp.size(); i++)
           {
             tempObj1 = new wrapperClass();
             tempObj1.billingAddress= opp[i].Shipment_Info__c;
                               }
             aReList1.add(tempObj1);        

             /* Below code commented by Kiranmai as Shipment Info field is split into multiple fields
             
             //------- Added by Sumit-----------  
             stringList= new List<String>(); 
                  
             if(aReList1[0].billingAddress!=NULL && aReList1[0].billingAddress!=''){
                List<String> stringList=(aReList1[0].billingAddress).split(',');
                for(integer i=0;i<stringList.size();i++){
                   all=all+stringList[i]+'<br/>';
                }
             } */
               
             all = all + opp[0].Shipping_Address_Line1__c + '<br/>';
             if(opp[0].Shipping_Address_Line2__c!=NULL && opp[0].Shipping_Address_Line2__c!=''){
                 all = all + opp[0].Shipping_Address_Line2__c + '<br/>';
             }
             
             if(opp[0].Shipping_Address_Line3__c!=NULL && opp[0].Shipping_Address_Line3__c!=''){
                 all = all + opp[0].Shipping_Address_Line3__c + '<br/>';
             } 
              
             if(opp[0].Shipping_City__c!=NULL && opp[0].Shipping_City__c!=''){
                 all = all + opp[0].Shipping_City__c + '<br/>';
             }
             
             if(opp[0].Shipping_State_Province__c!=NULL && opp[0].Shipping_State_Province__c!=''){
                 all = all + opp[0].Shipping_State_Province__c + '<br/>';
             }  
                 
             if(opp[0].Shipping_Zipcode__c!=NULL && opp[0].Shipping_Zipcode__c!=''){
                 all = all + opp[0].Shipping_Zipcode__c + '<br/>';
             }
             
             if(opp[0].Shipping_Country__c!=NULL && opp[0].Shipping_Country__c!=''){
                 all = all + opp[0].Shipping_Country__c + '<br/>';
             }
            /* all = all + opp[0].Shipping_City__c + ', '+opp[0].Shipping_State_Province__c + ' - ' + opp[0].Shipping_Zipcode__c + '<br/>';
             all = all + opp[0].Shipping_Country__c + '<br/>';*/

             all=all.remove('null');
                     
                /*-----------------------------------*/ 
      return aReList1;  
   }
           public class wrapperClass{
          // public String Item{get;private set;}
           public String productname{get; set;}
           public String BinItemCode{get;set;}
           public Decimal Quantity{get;set;}
           public Decimal totalamount{get;set;}
           public Decimal Subtotal{get;set;}
           public Decimal NonPickTotal{get;set;}                            
           public Decimal unitprice{get;set;}
           public date todaysdate{get;set;}
           public decimal extension{get;set;}
           public string LineNumber{get;set;}
           public string billingAddress{get;set;}
           public string splittedaddress{get;set;}
           public string productline{get;set;}
           public string wholeaddress{get;set;}
           public boolean Pick{get;set;}
           public date ScheduledShipDate{get;set;}
           public wrapperClass(){}                
       }
       
      
}
This is the complete controller .
Now Based on the Condition
Condition 1:

If the product line for the product selected in opportunity items is ‘DIE’ make following changes .

1) unit price should change to $.01. // Condition Works

2)Unit price just change on the PDF display only and with extended amount which will be quantity times .01.

  Extension = Quantity*0.01 // Condition Works
3)productname =BinItemcode // Condition Works
4)Subtotal = NonPickTotal //Condition doesnot work -------Here the value should change as per the logic written and display on the vf page the total should be 11 but its reflecting as 1100.



Condition 2:

If the product line for the product selected in opportunity items is '!DIE’ make following changes .

1) unit price should change to $1.

2)Extension =Extension

Any help very much appreciated.

 

 
ShotShot
Wow, as i understood, you change unitprice for tempObj, which you add to the appointmentList. And we get this data in:
<apex:repeat value="{!appointmentList}" var="line">
Then we get another data from opportunity, which are not connected to that tempObj changes.

So, you need to create in InvoiceController some fields:
public Decimal total;
public Decimal noPickTotal;
Which you will be change in getappointmentList.
After that you need to change from:
<apex:outputText value="{!opportunity.Non_Pick_Total__c}"></apex:outputText>
<apex:outputText value="{!opportunity.Non_Pick_Total__c + opportunity.Shipping_Charges__c}">
</apex:outputText>
To:
<apex:outputText value="{!total}"></apex:outputText>
<apex:outputText value="{!noPickTotal}"></apex:outputText>


 
nikkeynikkey
Hi Bogdan Kulyk
In the Wrapper class , i have the
public Decimal Subtotal{get;set;}
public Decimal NonPickTotal{get;set;}

without changing the Vf code , cant we go in writing the logic  to change the value.
ShotShot
Wrapping class doesnt have any connection to your VF, as it doesnt have ApexPages.StandardController in constructor, you or someone else created it for manipulating data inside controller, not as additional controller to VF.
So the 'total data' we have to get from the controller, thats why you need these fields in the controller, when you add them to controller, you will be able to get data in VF using {!fieldName}.

So add these fields to controller and inside getAppointmentList calculate these fields, then you will get them in VF page as i mention above.
nikkeynikkey
I tried with public List getappointmentList (){ public Decimal total; public Decimal NonPickTotal; i get an Error as :Illegal modifier on local variable at line 45 When i change it throws an Error as Unknown property 'OpportunityStandardController.NonPickTotal'
ShotShot
you have to add these fields to class InvoiceController, not to the method!! In method you will calculate them!
nikkeynikkey
I have added them to the class , Public Decimal Subtotal; Public Decimal NonPickTotal; public List getappointmentList (){ In method we have the logic present. Can please update the code with changes .