Showing posts with label Visualforce. Show all posts
Showing posts with label Visualforce. Show all posts
Thursday, 26 April 2018
Spinners : Salesforce Visualforce
13:51
<apex:actionStatus id="spinnerStatus">
<apex:facet name="start">
<div role="status" class="slds-spinner slds-spinner_large slds-spinner_brand">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</apex:facet>
</apex:actionStatus>
LIGHTNING DESIGN SYSTEM
<apex:commandButton styleClass="slds-button slds-button_success" status="spinnerStatus" title="Save" value="Save" reRender="showmsg" action="{!save}" />
<apex:facet name="start">
<div role="status" class="slds-spinner slds-spinner_large slds-spinner_brand">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</apex:facet>
</apex:actionStatus>
LIGHTNING DESIGN SYSTEM
<apex:commandButton styleClass="slds-button slds-button_success" status="spinnerStatus" title="Save" value="Save" reRender="showmsg" action="{!save}" />
Tuesday, 26 July 2016
How can I change the visualforce page to a public one?
22:30
Please follow the below steps for make visual force page public.
Please check the below links for more details.
https://developer.salesforce.com/page/An_Introduction_to_Force.com_Sites
https://help.salesforce.com/HTViewHelpDoc?id=sites_public_access_settings.htm
- go to Setup > Develop > Sites,
- register your Force.com subdomain name,
- create a new Force.com Site
- next to 'Site Visualforce Pages' click Edit
- add your page to the list of Enabled Visualforce Pages
Please check the below links for more details.
https://developer.salesforce.com/page/An_Introduction_to_Force.com_Sites
https://help.salesforce.com/HTViewHelpDoc?id=sites_public_access_settings.htm
how to display two objects fields in visualforce page by using wrapper class?
22:00
Please find below an example of how to accomplish this.
I've included 2 ways to do this:
Using a single query
Using a wrapper class My controller (AccountContactWrapperController.class):
public class AccountContactWrapperController {
public List<Account> accounts{get;set;}
public List<ACWrapper> ACWrappers{get;set;}
public AccountContactWrapperController(){
this.ACWrappers = new List<ACWrapper>();
this.accounts = new List<Account>();
//Get Accounts & Related Contacts in 1 query
List<Account> accs = [Select Id, Name, (Select Id, FirstName, LastName From Contacts) From Account Limit 1];
this.accounts = accs;
//Get Accounts & Contacts in separate queries for Wrapper
List<Account> accsForWrapper = [Select Id, Name From Account Limit 1];
List<Contact> consForWrapper;
Account acc;
if(accsForWrapper != null && !accsForWrapper.isEmpty()){
acc = accsForWrapper.get(0);
consForWrapper = [Select Id, FirstName, LastName From Contact Where AccountId =:acc.Id];
}
if(consForWrapper != null){
ACWrapper wrapper = new ACWrapper(acc, consForWrapper);
this.ACWrappers.add(wrapper);
}
}
public class ACWrapper{
public Account account{get;set;}
public List<Contact> contacts{get;set;}
public ACWrapper(Account acc, List<Contact> cons){
account = acc;
contacts = cons;
}
}
}
My VF page (AccountContactWrapperTest.page):
<apex:page controller="AccountContactWrapperController" >
<apex:form >
<!--Display Account & Contact info from 1 Query-->
<apex:pageBlock title="Info From Query">
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:Column value="{!a.Name}" />
<apex:Column headerValue="Contact Names">
<apex:repeat value="{!a.Contacts}" var="c">
{!c.FirstName} {!c.LastName} <br />
</apex:repeat>
</apex:Column>
</apex:pageBlockTable>
</apex:pageBlock>
<!--Display Account & Contact info from 1 Wrapper class-->
<apex:pageBlock title="Info From Wrapper class">
<apex:pageblocktable value="{!ACWrappers}" var="w">
<apex:Column value="{!w.account.Name}" />
<apex:column headervalue="Contact Names">
<apex:repeat value="{!w.contacts}" var="c">
{!c.FirstName} {!c.LastName} <br/>
</apex:repeat>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Output:
How can I show/ hide a div when the checkbox is selected?
20:00
Here is simple code With javascript.
<apex:page >
<head>
</head>
<apex:form >
<script>
function HideMsg(istrue)
{
var checkval = document.getElementById("msg")
if(istrue.checked )
{
var checkval = document.getElementById("msg").style.display='block';
}
else
{
var checkval = document.getElementById("msg").style.display='none';
}
}
</script>
<apex:pagemessages />
<div>
<apex:inputCheckbox id="checkbox" onchange="HideMsg(this);"/>
</div>
<div class="showp" style="display: none" id="msg">
<p>Hello World</p>
</div>
</apex:form>
</apex:page>
<apex:page >
<head>
</head>
<apex:form >
<script>
function HideMsg(istrue)
{
var checkval = document.getElementById("msg")
if(istrue.checked )
{
var checkval = document.getElementById("msg").style.display='block';
}
else
{
var checkval = document.getElementById("msg").style.display='none';
}
}
</script>
<apex:pagemessages />
<div>
<apex:inputCheckbox id="checkbox" onchange="HideMsg(this);"/>
</div>
<div class="showp" style="display: none" id="msg">
<p>Hello World</p>
</div>
</apex:form>
</apex:page>
Sunday, 23 August 2015
How to Set Dynamically Heder|footer in Visualforce page rander as Pdf
11:52
Rander As Pdf Header / Footer Visualforce || Saleforce
<apex:page renderAs="pdf" applyBodyTag="false" standardController="Account">
<head>
<style type="text/css" media="print">
@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>Account name is: {!Account.name} }</div>
</div>
<div class="footer">
<div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
</div>
<div class="content">
<p>Put all the Page content in this Div Tag </p>
</div>
</apex:page>
Wednesday, 12 August 2015
How Rendering a Visualforce page as PDF and saving it as an attachement in salesforce
13:55
How can U render a VF (Visualforce ) page as PDF and have a button on the page that saves this PDF as an attachment ?
Apex Class Code:
public class PdfRender{
public Account acc {get;set;}
public List<Account> ListAcc {get;set;}
public PdfRender(){
ListAcc = new List<Account>();
acc = new Account();
ListAcc =[Select Name,AccountNumber from Account Limit 10 ];
}
// return 'pdf' if the parameter 'p' has been passed to the page, or null
public String getSelectRender() {
if(ApexPages.currentPage().getParameters().get('p') != null)
return 'pdf';
else
return null;
}
public PageReference RenderedAsPDF() {
PageReference pdf = Page.RenderedAsPdf;
pdf.getParameters().put('p','p');
public Account acc {get;set;}
public List<Account> ListAcc {get;set;}
public PdfRender(){
ListAcc = new List<Account>();
acc = new Account();
ListAcc =[Select Name,AccountNumber from Account Limit 10 ];
}
// return 'pdf' if the parameter 'p' has been passed to the page, or null
public String getSelectRender() {
if(ApexPages.currentPage().getParameters().get('p') != null)
return 'pdf';
else
return null;
}
public PageReference RenderedAsPDF() {
PageReference pdf = Page.RenderedAsPdf;
pdf.getParameters().put('p','p');
// Below code to Save Pdf in attachment
Blob pdf1 = pdf.getcontentAsPdf();
Document d = new Document();
d.FolderId = UserInfo.getUserId();
d.Body = Pdf1;
d.Name = 'pdf_file.pdf';
d.ContentType = 'application/pdf';
d.Type = 'pdf';
insert d;
return pdf;
}
}
}
}
Visualforce Page Code:
<apex:page showHeader="false" sidebar="false" renderAs="{!SelectRender}" controller="PdfRender" >
<apex:pageBlock title="Demo Pdf View">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ListAcc}" var="ac">
<apex:column value="{!ac.name}"/>
<apex:column value="{!ac.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:commandButton action="{!RenderedAsPDF}" value="PDF View" id="theButton"/>
</apex:form>
</apex:page>
<apex:pageBlock title="Demo Pdf View">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ListAcc}" var="ac">
<apex:column value="{!ac.name}"/>
<apex:column value="{!ac.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:commandButton action="{!RenderedAsPDF}" value="PDF View" id="theButton"/>
</apex:form>
</apex:page>
How to Dynamically choosing render as PDF in Visualforce (Salesforce)
11:56
Render as PDF in Visualforce (Salesforce)
Apex Class Code :
public class PdfRender{
public Account acc {get;set;}
public List<Account> ListAcc {get;set;}
public PdfRender(){
ListAcc = new List<Account>();
acc = new Account();
ListAcc =[Select Name,AccountNumber from Account Limit 10 ];
}
// return 'pdf' if the parameter 'p' has been passed to the page, or null
public String getSelectRender() {
if(ApexPages.currentPage().getParameters().get('p') != null)
return 'pdf';
else
return null;
}
public PageReference RenderedAsPDF() {
PageReference pdf = Page.RenderedAsPdf;
pdf.getParameters().put('p','p');
return pdf;
}
}
public Account acc {get;set;}
public List<Account> ListAcc {get;set;}
public PdfRender(){
ListAcc = new List<Account>();
acc = new Account();
ListAcc =[Select Name,AccountNumber from Account Limit 10 ];
}
// return 'pdf' if the parameter 'p' has been passed to the page, or null
public String getSelectRender() {
if(ApexPages.currentPage().getParameters().get('p') != null)
return 'pdf';
else
return null;
}
public PageReference RenderedAsPDF() {
PageReference pdf = Page.RenderedAsPdf;
pdf.getParameters().put('p','p');
return pdf;
}
}
VF Code :
<apex:page renderAs="{!SelectRender}" controller="PdfRender" >
<apex:pageBlock title="Demo Pdf View">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ListAcc}" var="ac">
<apex:column value="{!ac.name}"/>
<apex:column value="{!ac.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:commandButton action="{!RenderedAsPDF}" value="PDF View" id="theButton"/>
</apex:form>
</apex:page>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ListAcc}" var="ac">
<apex:column value="{!ac.name}"/>
<apex:column value="{!ac.AccountNumber}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:commandButton action="{!RenderedAsPDF}" value="PDF View" id="theButton"/>
</apex:form>
</apex:page>
Saturday, 25 July 2015
How to create Contact in the Account As a Related list
10:59
This post is for insert ACCOUNT as well as its CONTACT.
e.g. see below screeshot :
Create one Visualforce Page.
Create one Class related to that visualforce Page.
Code of Visualforce Page :
<apex:page Controller="AccountDetail">
<apex:form >
<apex:pageblock title="Account Detail with contact">
<apex:pageblockButtons location="bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageblockButtons>
<apex:outputPanel >
<apex:pageblockSection title="Account Detail">
<apex:inputField value="{!account.Name}" />
<apex:inputField value="{!account.AccountNumber}"/>
<apex:inputField value="{!account.date__c}"/>
</apex:pageblockSection>
</apex:outputPanel>
<apex:outputPanel >
<apex:pageblockSection title="Contact Detail">
<apex:inputField value="{!contact.FirstName}" />
<apex:inputField value="{!contact.LastName}"/>
</apex:pageblockSection>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>
Code of Class related to above visualforce Page :
Public class AccountDetail{
public Account account{get;set;}
public Contact contact{get;set;}
public AccountDetail(){
account = new Account();
contact = new Contact();
}
public void Save(){
insert account;
contact.AccountId = account.Id;
insert contact;
update account;
}
}
Create one Class related to that visualforce Page.
Code of Visualforce Page :
<apex:page Controller="AccountDetail">
<apex:form >
<apex:pageblock title="Account Detail with contact">
<apex:pageblockButtons location="bottom">
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageblockButtons>
<apex:outputPanel >
<apex:pageblockSection title="Account Detail">
<apex:inputField value="{!account.Name}" />
<apex:inputField value="{!account.AccountNumber}"/>
<apex:inputField value="{!account.date__c}"/>
</apex:pageblockSection>
</apex:outputPanel>
<apex:outputPanel >
<apex:pageblockSection title="Contact Detail">
<apex:inputField value="{!contact.FirstName}" />
<apex:inputField value="{!contact.LastName}"/>
</apex:pageblockSection>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>
Code of Class related to above visualforce Page :
Public class AccountDetail{
public Account account{get;set;}
public Contact contact{get;set;}
public AccountDetail(){
account = new Account();
contact = new Contact();
}
public void Save(){
insert account;
contact.AccountId = account.Id;
insert contact;
update account;
}
}
Thursday, 16 July 2015
Adding help text for apex:inputText
11:47
In order to show help text in apex:inputText, "title" attribute is used.
Sample Code:<apex:page sidebar="false" >
<apex:form >
<apex:panelGrid columns="2" width="100%" cellpadding="5" cellspacing="5" >
<apex:outputtext value="Name"/>
<apex:inputtext title="Enter your Name" />
<apex:outputtext value="Age"/>
<apex:inputtext title="Enter your Age"/>
<apex:outputtext value="Total Experience"/>
<apex:inputtext title="Enter your total experience in IT" />
<apex:outputtext value="Skill"/>
<apex:inputtext title="Enter your skills. eg C, C++..." />
<apex:commandbutton value="Validate"/>
</apex:panelGrid>
</apex:form>
</apex:page> Output:
What is the difference between outputfield and outputtext?
11:41
apex:outputText: Displays text on a Visualforce page.
apex:outputField: A read-only display of a label and value for a field on a Salesforce object.
Sample Code:
Visualforce Page:
<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
<apex:pageBlock id="pg">
<apex:pageBlockSection columns="1">
<apex:outputText >Sample Output Text</apex:outputText>
<apex:outputField value="{!acct.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public class Sample {
public Account acct {get;set;}
public Sample() {
acct = [SELECT Name, Industry FROM Account LIMIT 1];
}
}
Output:
apex:outputField: A read-only display of a label and value for a field on a Salesforce object.
Sample Code:
Visualforce Page:
<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
<apex:pageBlock id="pg">
<apex:pageBlockSection columns="1">
<apex:outputText >Sample Output Text</apex:outputText>
<apex:outputField value="{!acct.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public class Sample {
public Account acct {get;set;}
public Sample() {
acct = [SELECT Name, Industry FROM Account LIMIT 1];
}
}
Output:
Subscribe to:
Posts (Atom)





