My requirement is whenever we update a record its updated version should be saved in attachments with date and time. I'm good with it but I'm using two VF pages one for edit page and other as detail page (GeneratingPdfPage2) for input to convert to pdf ("Here is my doubt why cant I use standard record detail page for imput to convert to pdf?") Some one please help me can I do this with out 2nd vf page. if I use same edit page for pdf purpose output pdf is getting all picklist values into it. Here is my apex code:
public class generatePdfAndAttach {
string projectRecordId{get; set;}
private final Account acct{get; set;}
public PageReference Save() {
Try{
system.debug('inside save and acc++'+acct);
upsert (acct);
system.debug('after upsert');
generatePdf();
system.debug('after generate pdf');
}
catch(system.dmlException e)
{
Apexpages.AddMessages(e);
return null;
}
return new PageReference('/'+projectRecordId);
}
public generatePdfAndAttach(ApexPages.StandardController standardPageController) {
this.acct = (Account)standardPageController.getRecord();
projectRecordId = ApexPages.CurrentPage().getparameters().get('id');
}
public PageReference generatePdf(){
Attachment att = new Attachment();
PageReference pdfPage = Page.GeneratingPdfPage2;//new PageReference('/'+projectRecordId);//Page.GeneratingPdfPage2;
pdfPage.getParameters().put('id',projectRecordId);
DateTime dt = datetime.now();
att.name =''+acct.name+' - '+dt+'.pdf';
// the contents of the attachment from the pdf
// return page content as blob type
Blob body;
try {
// returns the output of the page as a PDF
body = pdfPage.getContentAsPDF();
}
catch (VisualforceException e) {
body = Blob.valueOf('Can\'t get content as pdf');
}
att.body = body;
att.IsPrivate = false;
// Associate with project's record Id
att.parentid = projectRecordId;
att.ContentType = 'application/pdf';
insert att;
return new PageReference('/'+projectRecordId);
}
}
vf page 1:
<apex:page standardcontroller="Account" extensions="generatePdfAndAttach">
<apex:messages />
<apex:sectionheader title="{!$ObjectType.Account.label} Edit" subtitle="{!IF(ISNULL(Account.Name), 'New Account',Account.Name)}"/>
<apex:form >
<apex:pageblock mode="edit" title="{!$ObjectType.Account.label} Edit">
<apex:pageblockbuttons >
<apex:commandbutton value="Save" action="{!Save}" />
<apex:commandbutton value="Cancel" action="{!Cancel}"/>
</apex:pageblockbuttons>
<!-- ********** [Record Type : Master ] ********** -->
<apex:outputpanel >
<apex:pageblocksection title="Account Information" showheader="true" columns="2">
<apex:outputfield value="{!Account.OwnerId}"/>
<apex:inputfield value="{!Account.Phone}" required="false"/>
<apex:inputfield value="{!Account.Name}" required="true"/>
<apex:inputfield value="{!Account.Fax}" required="false"/>
<apex:inputfield value="{!Account.ParentId}" required="false"/>
<apex:inputfield value="{!Account.Rating}" required="false"/>
<apex:inputfield value="{!Account.AccountNumber}" required="false"/>
<apex:inputfield value="{!Account.Website}" required="false"/>
<apex:inputfield value="{!Account.Site}" required="false"/>
<apex:inputfield value="{!Account.TickerSymbol}" required="false"/>
<apex:inputfield value="{!Account.Type}" required="false"/>
<apex:inputfield value="{!Account.Ownership}" required="false"/>
<apex:inputfield value="{!Account.Industry}" required="false"/>
<apex:inputfield value="{!Account.NumberOfEmployees}" required="false"/>
<apex:inputfield value="{!Account.AnnualRevenue}" required="false"/>
<apex:inputfield value="{!Account.Sic}" required="false"/>
</apex:pageblocksection>
<apex:pageblocksection title="Address Information" showheader="true" columns="2">
<apex:inputfield value="{!Account.BillingStreet}" required="false"/>
<apex:inputfield value="{!Account.ShippingStreet}" required="false"/>
<apex:inputfield value="{!Account.BillingCity}" required="false"/>
<apex:inputfield value="{!Account.ShippingCity}" required="false"/>
<apex:inputfield value="{!Account.BillingState}" required="false"/>
<apex:inputfield value="{!Account.ShippingState}" required="false"/>
<apex:inputfield value="{!Account.BillingPostalCode}" required="false"/>
<apex:inputfield value="{!Account.ShippingPostalCode}" required="false"/>
<apex:inputfield value="{!Account.BillingCountry}" required="false"/>
<apex:inputfield value="{!Account.ShippingCountry}" required="false"/>
</apex:pageblocksection>
<apex:pageblocksection title="Additional Information" showheader="true" columns="2">
<apex:inputfield value="{!Account.CustomerPriority__c}" required="false"/>
<apex:inputfield value="{!Account.SLA__c}" required="false"/>
<apex:inputfield value="{!Account.SLAExpirationDate__c}" required="false"/>
<apex:inputfield value="{!Account.SLASerialNumber__c}" required="false"/>
<apex:inputfield value="{!Account.NumberofLocations__c}" required="false"/>
<apex:inputfield value="{!Account.UpsellOpportunity__c}" required="false"/>
<apex:inputfield value="{!Account.Active__c}" required="false"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="Description Information" showheader="true" columns="1">
<apex:inputfield value="{!Account.Description}" required="false"/>
</apex:pageblocksection>
</apex:outputpanel>
</apex:pageblock>
</apex:form>
vf page 2 (GeneratingPdfPage2):
<apex:page standardcontroller="Account" sidebar="false" showHeader="false" showChat="false">
<apex:messages />
<apex:sectionheader title="{!$ObjectType.Account.label} Detail" subtitle="{!Account.Name}"/>
<chatter:feedwithfollowers entityId="{!Account.Id}"/>
<apex:form >
<apex:pageblock mode="maindetail" title="{!$ObjectType.Account.label} Detail">
<apex:pageblockbuttons >
<apex:commandbutton value="Edit" action="{!Edit}"/>
<apex:commandbutton value="Delete" action="{!Delete}"/>
</apex:pageblockbuttons>
<!-- ********** [Record Type : Master ] ********** -->
<apex:outputpanel >
<apex:pageblocksection title="Account Information" showheader="false" collapsible="false" columns="2">
<apex:pageblocksectionitem >
<apex:outputlabel value="Account Owner"/>
<apex:outputpanel >
<apex:outputfield value="{!Account.OwnerId}"/>
<apex:outputlink value="{!URLFOR($Action.Account.ChangeOwner,Account.id)}" rendered="{!NOT(ISNULL(Account.Id))}">[Change]</apex:outputlink>
</apex:outputpanel>
</apex:pageblocksectionitem>
<apex:outputfield value="{!Account.Phone}"/>
<apex:outputfield value="{!Account.Name}"/>
<apex:outputfield value="{!Account.Fax}"/>
<apex:outputfield value="{!Account.ParentId}"/>
<apex:outputfield value="{!Account.Rating}"/>
<apex:outputfield value="{!Account.AccountNumber}"/>
<apex:outputfield value="{!Account.Website}"/>
<apex:outputfield value="{!Account.Site}"/>
<apex:outputfield value="{!Account.TickerSymbol}"/>
<apex:outputfield value="{!Account.Type}"/>
<apex:outputfield value="{!Account.Ownership}"/>
<apex:outputfield value="{!Account.Industry}"/>
<apex:outputfield value="{!Account.NumberOfEmployees}"/>
<apex:outputfield value="{!Account.AnnualRevenue}"/>
<apex:outputfield value="{!Account.Sic}"/>
<apex:outputfield value="{!Account.AccountStatus__c}"/>
<apex:pageblocksectionitem />
<apex:outputfield value="{!Account.Potential_Value__c}"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="Address Information" showheader="false" collapsible="false" columns="2">
<apex:pageblocksectionitem >
<apex:outputlabel value="Billing Address"/>
<apex:outputpanel >
<apex:outputfield value="{!Account.BillingStreet}"/>
<br/>
<apex:outputfield value="{!Account.BillingCity}"/> ,
<apex:outputfield value="{!Account.BillingState}"/>
<apex:outputfield value="{!Account.BillingPostalCode}"/>
<br/>
<apex:outputfield value="{!Account.BillingCountry}"/>
</apex:outputpanel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Shipping Address"/>
<apex:outputpanel >
<apex:outputfield value="{!Account.ShippingStreet}"/>
<br/>
<apex:outputfield value="{!Account.ShippingCity}"/> ,
<apex:outputfield value="{!Account.ShippingState}"/>
<apex:outputfield value="{!Account.ShippingPostalCode}"/>
<br/>
<apex:outputfield value="{!Account.ShippingCountry}"/>
</apex:outputpanel>
</apex:pageblocksectionitem>
</apex:pageblocksection>
<apex:pageblocksection title="Additional Information" showheader="false" collapsible="false" columns="2">
<apex:outputfield value="{!Account.CustomerPriority__c}"/>
<apex:outputfield value="{!Account.SLA__c}"/>
<apex:outputfield value="{!Account.SLAExpirationDate__c}"/>
<apex:outputfield value="{!Account.SLASerialNumber__c}"/>
<apex:outputfield value="{!Account.NumberofLocations__c}"/>
<apex:outputfield value="{!Account.UpsellOpportunity__c}"/>
<apex:outputfield value="{!Account.Active__c}"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="System Information" showheader="false" collapsible="false" columns="2">
<apex:pageblocksectionitem >
<apex:outputlabel value="Created By"/>
<apex:outputpanel >
<apex:outputfield value="{!Account.CreatedById}"/> ,
<apex:outputfield value="{!Account.CreatedDate}"/>
</apex:outputpanel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Last Modified By"/>
<apex:outputpanel >
<apex:outputfield value="{!Account.LastModifiedById}"/> ,
<apex:outputfield value="{!Account.LastModifiedDate}"/>
</apex:outputpanel>
</apex:pageblocksectionitem>
</apex:pageblocksection>
<apex:pageblocksection title="Description Information" showheader="false" collapsible="false" columns="1">
<apex:outputfield value="{!Account.Description}"/>
</apex:pageblocksection>
</apex:outputpanel>
</apex:pageblock>
</apex:form>
<!-- ********** [Related Lists for Record Type : Master ] ********** -->
<apex:outputpanel >
<apex:relatedlist list="Contacts" title="Contacts"/>
<apex:relatedlist list="AccountContactRoles" title="Contact Roles"/>
<apex:relatedlist list="AccountTeamMembers" title="Account Team"/>
<apex:relatedlist list="Opportunities" title="Opportunities"/>
<apex:relatedlist list="Cases" title="Cases"/>
<apex:relatedlist list="OpenActivities" title="Open Activities"/>
<apex:relatedlist list="CombinedAttachments" title="Notes & Attachments"/>
<apex:relatedlist list="ActivityHistories" title="Activity History"/>
<apex:relatedlist list="AccountPartnersFrom" title="Partners"/>
<apex:relatedlist list="ProcessSteps" title="Approval History"/>
</apex:outputpanel>