Tuesday, June 27, 2017

Visual force pages in salesforce:

What is the Visualforce Page Size

A single page can hold up to 1 MB of text, or approximately 1,000,000 characters

What is Visualforce?

Visualforce is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the Force.com platform. The Visualforce framework includes a tag-based markup language, similar to HTML.

In the Visualforce markup language, each Visualforce tag corresponds to a fine-grained user interface component, such as a section of a page, a related list, or a field. The behavior of Visualforce components can either be controlled by the same logic that is used in standard Salesforce pages, or developers can associate their own logic with a controller class written
in Apex





Where Can Visualforce Pages Be Used?
Developers can use Visualforce pages to:
• Override standard buttons, such as the New button for accounts, or the Save button for contacts
• Override tab overview pages, such as the Accounts tab home page
• Define custom tabs
• Embed components in detail page layouts
• Create dashboard components or custom help pages
• Customize, extend, or integrate the sidebars in the Salesforce console (custom console components)

How can we implement pagination in Visualforce?

To control the number of records displayed on each page, we use pagination. By default, a list controller returns 20 records on the page. To customize it, we can use a controller extension to set the pageSize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<apex:page standardController="Account" recordSetvar="accounts">

 <apex:pageBlock title="Viewing Accounts">

 <apex:form id="theForm">

 <apex:pageBlockSection >

 <apex:dataList var="a" value="{!accounts}" type="1">

 {!a.name}

 </apex:dataList>

 </apex:pageBlockSection>

 <apex:panelGrid columns="2">

 <apex:commandLink action="{!previous}">Previous</apex:commandlink>

 <apex:commandLink action="{!next}">Next</apex:commandlink>

 </apex:panelGrid>

 </apex:form>

 </apex:pageBlock>

</apex:page>



How to get the UserID of all the currently logged in users using Apex code?

You can get the ID’s of all the currently logged in users by using this global function: UserInfo.getUserId().

How to find IP Address Geolocation In salesforce?

If you would like to know your ip address location based on the user ip address. here is best option you can go with.

I have created a visualforce page and an apex controller that makes a callout to external application with the user logged in ip address and will get back the response and displays in vf page.

Visualforce Page:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<apex:page action="{!getipaddress}" controller="FindIpAddress">
Country:{!country}
  
Isp:{!isp}
  
IP:{!ip}
  
Latitude:{!latitude}
  
Longitude{!longitude}
  
TimeZone: {!timezone}
  
</apex:page>
Apex class:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class FindIpAddress {
    public String country {get;set;}
    public String isp {get;set;}
    public String ip {get;set;}
    public integer latitude {get;set;}
    public integer longitude {get;set;}
    public String timezone {get;set;}
   
 public void getipaddress() {
  string ReturnValue = ''; 
  ReturnValue = ApexPages.currentPage().getHeaders().get('True-Client-IP');
  if (ReturnValue == '' || ReturnValue == null) {
   ReturnValue = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
  }
  if (ReturnValue == '' || ReturnValue == null) {
   ReturnValue = ApexPages.currentPage().getHeaders().get('X-Forwarded-For');
  }
  Http h = new Http();
  HttpRequest req = new HttpRequest();
  req.setEndpoint('http://www.telize.com/geoip/'+ReturnValue);
  req.setMethod('GET');
  HttpResponse res;
  try{
   res = h.send(req);
   Map<string object="">m = (Map<string object="">)JSON.deserializeUntyped(res.getbody());
   country =(String)m.get('country');
   isp=(String)m.get('isp');
   ip=(String)m.get('ip');
   latitude=(Integer)m.get('latitude');
   longitude =(Integer)m.get('longitude');
   timezone =(String)m.get('timezone');
  }catch(Exception e){
  }
 }
}

How to add visualforce page in home page?


If you want add visualforce page to home please follow the below

Step 1:-

Setup-->Customize-->Home--> Home Page components
click on Home Page components
In custom components section click on New
Give the name you want
We can show four different components in that Choose Visualforce Area click next

Component Position: Wide (Right) Column
Visualforce Page : Graduate List
Height (in pixels): 400
click save

Step 2:-

Setup-->Customize-->Home-->Home Page Layouts
In Home Page Layouts click on default then click on edit
In Select Wide Components to Show section check the Graduate List
then click next and then save
now check it will display like below.


How to rendered Visualforce page that renders as PDF,when a button is clicked?


We may need Visualforce page that renders as PDF ,when a button is clicked
?
1
2
3
4
5
6
7
8
<apex:page controller="MyController" id="myPage" renderas="{!if($CurrentPage.parameters.isPdf == null, null, 'pdf')}">
    <apex:pageblock title="PageBlock">
        <apex:pageblocksection title="Section1"> Some Text Here </apex:pageblocksection>
    </apex:pageblock>
    <apex:form>
        <apex:commandlink action="/apex/RenderasPDFPage?isPdf=true" value="PDF">
    </apex:commandlink></apex:form>
</apex:page>

How to print a Visualforce page in Salesforce?


To print visualforce page add below line to visualforce page.
?
1
2
<apex:commandlink onclick="window.print();" value="Print">
</apex:commandlink>

How to use Read more in Visualfoce page ?

?
1
2
3
4
lign="justify">
<apex:outputtext value="{!LEFT(p.KEvents__Description__c,250)}"></apex:outputtext>
<apex:outputlink style="decoration: none;" value="{!DisplayProgramPage}?id={!p.id}"
font color ="#3399f3">Read more</apex:outputlink>

Output:

How to create expand and collapse link for an Div in Visualforce page using Jquery?


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<apex:page sidebar="false" standardcontroller="Account">   
<apex:form>
    <apex:pageblock>
        <apex:pageblocksection>
            <apex:outputfield value="{!Account.Name}">
            </apex:outputfield>
            <apex:pageblocksectionitem>   
                <apex:outputlabel value="Description"> </apex:outputlabel>
                <apex:outputpanel>                   
                    <div class="showmorefirm">
<div class="moreblockfirm" id="Des">
<apex:outputfield value="{!Account.Description}"> </apex:outputfield>
                     </div>
</div>
</apex:outputpanel>
            </apex:pageblocksectionitem>
            <apex:outputfield value="{!Account.Phone}">
           </apex:outputfield>
            <apex:outputfield value="{!Account.Active__c}">
             </apex:outputfield>
        </apex:pageblocksection>
    </apex:pageblock>
</apex:form>
</apex:includescript></apex:page>
Output:

How to remove last character from a String in Apex?

?
1
2
3
String body= '{"userID" : "115f0000001i1gu"}';
String finalBody= body.removeEnd('}');
system.debug('Value is ' + finalBody);
output: {"userID" : "115f0000001i1gu"

How to disable copy,paste and right click in Visualforcepage?


By using the JavaScript we can disable the Copy ,Paste and Right click so we can restrict user to see pagesource.

VisualforcePage:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<apex:page standardcontroller="Contact">
  <script>
      function DisableRightClick(event){   
        if (event.button==2)
        {
            alert("Right Click is not Allowed");      
        }
      }
     function DisableCtrlKey(e){
         
        var code = (document.all) ? event.keyCode:e.which;
         if (parseInt(code)==17){
            alert("Please re-type your email address");          
        }  
    }
  </script>
  <apex:form>
      <apex:pageblock title="Create Contact" onmousedown="DisableRightClick(event)">
          <apex:pageblockbuttons>
              <apex:commandbutton value="Save" action="{!save}">
          </apex:commandbutton></apex:pageblockbuttons>
          <apex:pageblocksection columns="1">
              <apex:inputfield value="{!Contact.Firstname}">
              <apex:inputfield value="{!Contact.LastName}">
              <apex:inputfield value="{!Contact.Email}">
              <apex:inputtext value="{!Contact.Email}" label="Re-Type Email Id" onkeydown="DisableCtrlKey(event)">             
              <apex:inputfield value="{!Contact.Phone}">             
          </apex:inputfield></apex:inputtext></apex:inputfield></apex:inputfield></apex:inputfield></apex:pageblocksection>
      </apex:pageblock>
  </apex:form>
</apex:page>

How do I to stop Visualforce page from rendering when i click on Outputlink or Commond link?


?
1
2
3
<apex:outputlink onclick="openPopup('{!$Page.SSProductCreateReviewPage}','{!pro.product__r.id}'); return false;">
 Write a Review
</apex:outputlink>

How to Open a Visual force page as pop up from another visual force page with parameters.


?
1
2
3
<apex:outputlink onclick="openPopup('{!$Page.PageDemo}','somevalue');">
    Click
</apex:outputlink>







No comments:

Post a Comment