ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

WorkAround for PDF Rendering in SF1

Home / Article & Blogs / Apex / WorkAround for PDF Rendering in SF1
By Team ABSYZ inApex, Uncategorized

Salesforce1 as a new mobile interface for everything in Salesforce. It’s possible to publish a visualforce page to mobile devices.

One key developer feature is that any visualforce page, can be embedded in the Salesforce1 mobile app without extra coding – just by making the Visualforce page ‘available for mobile’ (checkbox in the VF page editing screen in Salesforce admin UI, not Salesforce1).

There are some limitations in Salesforce1. One of the limitations of SF1 is PDF rendering, by setting renderAs=”PDF” on, isn’t supported for pages in Salesforce1.

For Example, We have a button ‘Contact Pdf’ on the detail page of contact, upon click on the button generates Pdf in desktop as shown in Figures.

Capture new.PNG

Capture pdf.PNG

If we click the same button in SF1, it gives blank page as Pdf rendering is not supported in SF1.

Capture22

Capture3

Workaround :

The workaround is by creating a visualforce page that asks for email id in SF1. Once the user gives the email id, the pdf will be emailed to the given mail id instead of rendering on the page.

We can use same button(eg..here ‘Contact Pdf’) in Desktop and in SF1, which generates Pdf directly in Desktop and displays a visualforce page (eg: here ‘ContactEmailPage’)which asks for an email id in SF1.So we require an intermediate page which redirects to Desktop as well as SF1

Visualforcepage which redirects to SF1 and Desktop.

[sourcecode language=”java”]
<apex:page StandardController=”Contact”>
<script language=”javascript” type=”text/javascript”>
window.onload = function() {
var myUrl = “{!$Site.Prefix}/apex/ContactEmailPage?id={!Contact.Id}”;

if( (typeof sforce != ‘undefined’) && (sforce != null) ) {
// Salesforce1 navigation
sforce.one.navigateToURL(myUrl);
} else {
// Set the window’s URL using a Visualforce expression for redirection in
desktop
window.location.href =”{!$Site.Prefix}/apex/OrderLetterToCustomerPage”;
}
}

</script>
</apex:page>
[/sourcecode]

Visualforce page which is to be rendered as Pdf
Save it as ‘OrderLetterToCustomerPage’

[sourcecode language=”java”]
<apex:page renderAs=”PDF” >
<apex:image id=”theImage” value=”{!$Resource.AbsyzNew}” width=”700″ height=”170″ />
<h3 style=”text-align: center”>This is Sample PDF Page</h3>
<div class=’letterBody’>
Thank you for the order!!!
It has been processed and is in production.
Your product will be delivered in a week.
Please provide us with the needed date.
Otherwise, storage charges may be applied.

Regards,
Team ABSYZ</div>
</apex:page>
[/sourcecode]

Now create a visualforce page for SF1, asks for an email id to send the Pdf.
Save it as ‘ContactEmailPage’

[sourcecode language=”java”]
<apex:page standardController=”Contact” showHeader=”false” standardStylesheets=”True” extensions=”sendEmail” >
<apex:image id=”theImage” value=”{!$Resource.AbsyzNew}” width=”430″ height=”100″/>
<H1>To get PDF in the mail, Give mail id in the text box and click ‘Email PDF’ button</H1>
<H1>PDF will be mailed to the given Email Id</H1>

<apex:form >
<H1 style=”font-size:15px”><span>Email id:</span></H1>

<apex:inputText label=”Email” value=”{!emailid}” style=”border-color: #696363 #696363;font-size:15px;margin-left:2px”></apex:inputText>
<apex:commandButton value=”Email PDF” action=”{!send}” style=”font-size:15px” />
<apex:commandButton onclick=”sforce.one.navigateToURL(‘/{!Contact.id}’)” value=”Back” style=”font-size:15px” />
</apex:form>
</apex:page>
[/sourcecode]

Controller ‘SendEmail’ for the page.

[sourcecode language=”java”]
public with sharing class sendEmail{

public String subject { get; set; }
public String body { get; set; }
public String emailid{get; set;}
private final Contact Con;

public sendEmail(ApexPages.StandardController controller) {
Con= [SELECT Name,id,email
FROM Contact
WHERE Id=:ApexPages.currentPage().getParameters().get(‘id’)];
}
public Contact getContact() {
return Con;
}
public PageReference send() {

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
PageReference pdf = Page.OrderLetterToCustomerPage;
pdf.getParameters().put(‘id’,(String)Con.id);
pdf.setRedirect(true);
Blob b = pdf.getContentAsPdf();

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setContentType(‘application/pdf’);
efa.setFileName(‘attachment.pdf’);
efa.setBody(b);
String addresses;
addresses=emailid;
String[] toAddresses = addresses.split(‘:’, 0);
email.setSubject( subject );
email.setToAddresses( toAddresses );
email.setPlainTextBody(‘Find the Attachment’);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
// Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
}
[/sourcecode]

Now upon click on ‘Contact Pdf’ button in SF1, the following page will get opened.

Capture22

Capture18.PNG

By giving the email id in the text box and click ‘Email Pdf’ button.The required Pdf will be emailed to the given email id. Using this workaround we can achieve Pdf rendering in SF1.

Capture19.PNG

Limitation in SF1Limitations of Salesforce1Navigation in Salesforce1PDF Rendering in SF1Render as PDF in Salesforce1SalesforceSalesforce1SF1
135
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

All About The OmniStudio FlexCards

All About The OmniStudio FlexCards

Boost Customer Experience With Repeater Widget in CRM Analytics

Boost Customer Experience With Repeater Widget in CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Net zero as a Service In CPG Industry

Net zero as a Service In CPG Industry

How Do We Import an External Library into Salesforce Lightning?

How Do We Import an External Library into Salesforce Lightning?

  • Previous PostDropbox Integration with Salesforce
  • Next PostAutomate metadata backup of your Salesforce org with the help of ANT and GIT

Related Posts

HOW THE TALENTS ARE TRAINED AT ABSYZ
Uncategorized

HOW THE TALENTS ARE TRAINED AT ABSYZ

Why choose Salesforce Integration Partners?
Salesforce Implementation Uncategorized

Why choose Salesforce Integration Partners?

Integrate SharePoint with Salesforce using Microsoft Graph API
Apex Integration Salesforce

Integrate SharePoint with Salesforce using Microsoft Graph API

Cyber-security in an uncertain world
Apex

Cyber-security in an uncertain world

1 Comment

  1. Alexandre
    Reply
    5 July 2019

    Hi,

    I try to adapt your tutoriel to a custom object but it didn’t work at all …

    Can i contact you for showing my code maybe you have a solution.

    Thanks a lot for your help !

    – Alexandre

    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT