Monday, 23 December 2013

Add PDF VF-Page to Notes and Attachment from custom button and refresh current page.





Hi Friends,


In this post i m writing how to add the attachment to Note & Attachment of Salesforce.com from VF-Page which is rendered as “pdf” from detail page Custom button.

Here the Custom button code its of onclick java script behaviour:-

               window.showModalDialog('/apex/PDF_Page?id={!Lead.Id}','',"
           dialogWidth:800px;dialogHeight:500px; center:yes | no | 1 | 0 | on | off");
           location.reload(true);

<apex:page renderAs="pdf" standardController="Lead" extensions="PDF_Page_Controller" action="{!savePDF}">
This is the Pdf page of Lead "{!lead.Name}".
</apex:page>
view raw PDF_Page hosted with ❤ by GitHub
public class PDF_Page_Controller{
Lead lead {get;set;}
public PDF_Page_Controller.PDF_Page_Controller(ApexPages.StandardController controller){
lead = (Lead)controller.getRecord();
}
public void savePDF(){
PageReference PR = Page.PDF_Page_demo;
Attachment att = new Attachment();
att.Name = lead.Name + '.pdf';
att.ParentId = lead.Id;
att.body = PR.getContentAsPdf();
insert att;
}
}
<apex:page renderAs="pdf" standardController="Lead" extensions="PDF_Page_Controller">
This is the Pdf page of Lead "{!lead.Name}".
</apex:page>
view raw PDF_Page_demo hosted with ❤ by GitHub

Here i used two VF-Pages to avoid recursive calling of VF Page because I am saving Attachment of page to Notes and Attachment of same object.

Note:-
Remember not to call the method from  "PDF_Page_demo".

Happy Coding...:)

here the sceern shots:-



Tuesday, 17 December 2013

Show Radio Button on the VF page


Hi Guys,

here the example to show the Radio buttons on the VF Page and toggle between them,

Controller Class And VF Page:-


<apex:page controller="Radio_Ex">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Radio Button">
<apex:pageBlockSection>
<apex:outputLabel value="Did you understands this example?"/>
<apex:selectRadio title="Select" value="{!answer}">
<apex:selectOptions value="{!items}" />
</apex:selectRadio>
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
view raw Radio_button_ex hosted with ❤ by GitHub
public class Radio_Ex{
Public String answer{set;get;}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Yes','Yes'));
options.add(new SelectOption('No','No'));
return options;
}
}
view raw Radio_Ex hosted with ❤ by GitHub
this is the screen shot of the VF page.