Thursday, 28 January 2016

How to Display Header and Footer on PDF Generation Salesforce


Sample code is given below.

Apex code:

public class testpdf1
{
    public list<Account> opp{get;set;}

    public testpdf1()
    {
           opp=[SELECT Name  from Account limit 50];    
    }


}


Visualforce page:

<apex:page renderAs="pdf" Controller="testpdf1">

        <head>

                <style type="text/css" media="print">
                       @page {
                                      size: 8.5in 11in;/* width height */
                                 }
                       
                       @page {

                                 
                                 @top-center {

                                       content: element(header);

                                 }

                                 @bottom-left {

                                     content: element(footer);

                                 }

                            }

                                     div.header {

                                      padding: 10px;

                                      position: running(header);

                           }
                       div.footer {

                                display: block;

                             padding: 5px;

                               position: running(footer);

                      }

                                     .pagenumber:before {

                                        content: counter(page);

                       }

                                   .pagecount:before {

                             content: counter(pages);

                        }

                    </style>

              </head>



           <div class="header">

              <div align="right">Header</div>

           </div>

           <div class="footer">

                <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>

          </div>

          <div class="content">

               <p><apex:repeat value="{!opp}" var="item">
            <tr>
                <td class="tableContent">{!item.Name}</td>
               
            </tr>
        </apex:repeat></p>

          </div>

</apex:page>

NoteIf u are not able to get output please change version .
In visualforce go to:Version settings change salesforce Api  version to  26.0

Disable Picklist field based on another picklist Value using JQuery In Visualforce


Sometime we want to disable picklist field based on another picklist field value like below.



In the above we can see if the Account Type is Partner then Industry Vertical (Picklist Field) is disable this can be achieved using below code.


<apex:page sidebar="false" standardController="Account">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Account.Type}" id="type"/>
                <apex:inputField value="{!Account.Phone}" id="Phone"/>
                <apex:inputField value="{!Account.AccountNumber}" id="actNumber"/>
                <apex:inputField value="{!Account.Industry}" id="industry"/>
                <apex:inputField value="{!Account.AnnualRevenue}" id="anualReven"/>
                 
            </apex:pageBlockSection>   
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>   
        </apex:pageBlock>   
    </apex:form> 
    <script>
        $(window).load(function(){
            $("[id$=type]").change(function(){
                if(this.value=="Partner"){
                        $("[id$=Phone]").val("");
                        $("[id$=actNumber]").val("");
                        $("[id$=industry]").val("");
                        $("[id$=anualReven]").val("");
                      
                        $("input[id$=Phone]").prop("disabled",true);                       
                       $("[id$=Phone]").prop("disabled",true);
                        $("[id$=actNumber]").prop("disabled",true);
                        $("[id$=industry]").prop("disabled",true);
                        $("[id$=anualReven]").prop("disabled",true);
                      
                }
                else{
                      $("[id$=Phone]").prop("disabled",false);
                        $("[id$=actNumber]").prop("disabled",false);
                        $("[id$=industry]").prop("disabled",false);
                        $("[id$=anualReven]").prop("disabled",false);
                       
                }               
            });
        });
    </script>
</apex:page>

Display Multi-Select Picklist field as CheckBox field on Web-to-Lead



Sometime we use multi-select picklist fields on lead object to capture more than once choice submitted by our customers/prospects in response to certain questions.

A sample business scenario could be, if we ask our customers/prospects to respond which all our services they are interested in.

In salesforce if we use a Picklist (Multi-Select) field, that solves our purpose.


Now if we want the same information to be captured from a web page through the web-to-lead integration, we can simply generate the salesforce code for the multi-select picklist field.

However if we see the web form output for the multi-select picklist field, it doesn’t look so great and while filling the web form end user has to press the Ctrl key in order to select more than one choice.


How about if on the web form we provide a user-friendly interface by replacing the multi-select picklist field with multiple check boxes? Sounds interesting! Isn’t it?


Okay, so if we want to achieve the above output on our web form, we need 3 additional check box fields in salesforce lead object in order to do the mapping with web-to-lead integration.

But NO, we are not going to create 3 fields, where we just needed one field in salesforce lead object.

Here is how we can map the salesforce multi-select picklist field with multiple checkboxes on the web form.

Replace your salesforce generated web-to-lead code for multi-select picklist field with below code.

Please specify your Interest Areas:

Salesforce Customization: <input  id="00NG000000ETZDd" name="00NG000000ETZDd" type="checkbox" value="Salesforce Customization" /><br>

Salesforce Development: <input  id="00NG000000ETZDd" name="00NG000000ETZDd" type="checkbox" value="Salesforce Development" /><br>

Salesforce Adoption: <input  id="00NG000000ETZDd" name="00NG000000ETZDd" type="checkbox" value="Salesforce Adoption" /><br>

The ID "00NG000000ETZDd" represents the API ID of salesforce multi-select picklist field.

Tools for Lightning Web Component Development

 Below are the tools required for Web Component Development 1. Chrome Browser (Prefered) You can download it from Google 2. Visual Studio Co...