1

Can any one help me on this .I have created a custom visual force page on "Opportunity "object .I have conditions where i need to change the field label name and its value Based on Condition in a Visual Force page in PDF Format.Can we do this .Any Suggestion Plz.

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

  1. unit price should change to $.01

  2. in the item field replace with bin item code.

The Unit price value works fine.Now can we change the field name and its value in vf page.

PFA Screen Shot :

enter image description here

Visual Force Page :

     <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="9" 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==true, 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>
</table>

Apex Class :

    public with sharing class InvoiceController {
           List<wrapperClass> appointmentList {get;set;}
           List<wrapperClass> appointmentList1 {get;set;} 
           public list<string> addaress{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;}
   //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
                          FROM OpportunityLineItem where OpportunityId=:oppId]; 
                          system.debug('HHHHHHHHHH'+OPplineitem.size());

                   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.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;
                      String productname='BinItemCode';

                     }
                 else
                     {
                     tempObj.unitprice=OPplineitem[i].ListPrice;
                     tempobj.extension=OPplineitem[i].Extension__c;
                     String productname='Item';
                     }
                     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;private set;}
           public String BinItemCode{get;set;}
           public Decimal Quantity{get;set;}
           public Decimal totalamount{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(){}                
       }
}

1 Answer 1

1

Make the change in your controller. Just add a variable to hold a string for the Class Name of the table column header along with a getter and setter method for it. Pass it to the page depending on the same conditionals you're using for the Unit Price change.

In your VF where you do your table cell heading declarations:

<table >
    <tr>
    <td class="header-table-heading">{!Item}</td>

Note: be sure to add the additional class in the CSS above if you use this approach.

In your controller:

public string Item {get; private set;}

if(OPplineitem[i].PricebookEntry.Product2.Product_Line__c=='DIE') 
                 {
                  tempObj.unitprice=0.01;
                  tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice;
                  string Item = 'BinItemCode';
                 }

                 else
                 {
                 tempObj.unitprice=OPplineitem[i].ListPrice;
                 tempobj.extension=OPplineitem[i].Extension__c;
                 string Item = 'Item';
                 }

Note: since the above is part of a wrapper, you'll need to structure this differently. I was mostly trying to illustrate the if-else condition since you didn't include all of your code.

8
  • :Can u help me out with an example.My controller is completely written on a wrapper class.Their is no table name .
    – nikkey
    Feb 4, 2015 at 16:18
  • See some sample code above. Was written on the fly and may contain syntax errors. You'll want to test and debug, but this should illustrate the concept of what you'll want to do.
    – crmprogdev
    Feb 4, 2015 at 17:31
  • @ crmprogdev:The "Item" is referenced with "Product name" field.I tried the using the product name ,but the label name does not get change.I have updated the code completely
    – nikkey
    Feb 4, 2015 at 18:00
  • Am I correct that you could potentially have some products where Product_Line__c=='DIE' and others in your wrapper where Product_Line__c!='DIE'? If so, it would seem that you'd want to have both columns available in your table and use which ever one was appropriate according to the value that was returned. From your code, productname= OPplineitem[i].PricebookEntry.Product2.Name; It changes with each line item. You'll need to pick one and pass it to a diff var name assuming you want to count on the Product_Line__c=='DIE' condition to always be true.
    – crmprogdev
    Feb 4, 2015 at 18:32
  • :Correct me if im wrong product and opportunityline item are the same .Product_line__c is a custom field in on product object.I tried ,but the label name does not get change.Any help plz.
    – nikkey
    Feb 5, 2015 at 11:32

You must log in to answer this question.

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