• kfenn
  • NEWBIE
  • 0 Points
  • Member since 2012
  • Sogeti

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

I am trying to create a simple VF page that renders a PDF from HTML that is passed in by my controller. Using the VF code below, the dynamic HTML renders properly as a regular VF page, but when I add the "renderAs="PDF" to my page tag, only the raw HTML appears in the PDF and not the properly rendered HTML.

 

The following correctly renders the dynamic HTML:

<apex:page controller="trainingLetterPDFController" >
    <apex:outputText value="{!LetterHTMLBody}" escape="false"/>
</apex:page>

 The following renders the page as a PDF showing the raw HTML text:

<apex:page controller="trainingLetterPDFController" renderAs="PDF">
    <apex:outputText value="{!LetterHTMLBody}" escape="false"/>
</apex:page>

 

Any suggestions on how to get this dynamic HTML to render in the PDF?

Thanks!

  • July 09, 2013
  • Like
  • 0

I am a very novice developer and am working on an Email Services class that will parse contact information from applications submitted via our Web site's simple application form. The data is stored in a custom object that we use to track applicants. The email that we receive from the Web site form looks like this:

 

First Name: Joe
Last Name: Test
Position Applying For: Editor/Proofer
EMail Address: test@testemail.com
Address1: 
Address2: 
City: 
State: 
Zip: 
Telephone Number: xxx-xxx-xxxx
Alternate Telephone Number: 
How did you hear about us? Monster.com
If other, please specify: 
Most Recent Employer: Self-Employed

The Email Services code processes this fine when I send this email as a test from my Outlook email client, but when I set up the Web site form to automatically send these applications to the Email Services email address, I receive an email with the following error:

 

"The attached message was sent to the Email Service address <submit_resume@4r0eqtpjrqi4qsx8nryitfmzj.8dnvxeae.c.apex.salesforce.com> but could not be processed because the following error occurred:

 

554 System.StringException: Ending position out of bounds: -1

 

Class.employeeApplication.handleInboundEmail: line 11, column 28 External entry point"

 

What would be different about sending the email from my email address versus having our Web site's form handler send it? My email services code is below for reference:

global class employeeApplication implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          
          SFDC_Employee__c candidate = new SFDC_Employee__c();
          candidate.Employee_Status__c = 'Interested';
          candidate.Initial_Contact_Date__c = System.now().date();
          
          String app = email.plainTextBody;
         
          candidate.Name = app.substring(app.indexof('First Name: ') + 12, app.indexof('Last Name:') - 1) + app.substring(app.indexof('Last Name: ') + 11, app.indexof('Position'));
          candidate.Position__c = app.substring(app.indexof('Position Applying For: ') + 23, app.indexof('EMail Address:'));
          candidate.Email_Address__c = app.substring(app.indexof('EMail Address:') + 15, app.indexof('Address1:'));
          candidate.Home_Address_del__c = app.substring(app.indexof('Address1:') + 10, app.indexof('Address2:')) + app.substring(app.indexof('Address2:') + 10, app.indexof('City:'));
          candidate.Home_City_del__c = app.substring(app.indexof('City:') + 6, app.indexof('State:'));
          candidate.Home_State_del__c = app.substring(app.indexof('State:') + 7, app.indexof('Zip:'));
          candidate.Home_Zip_del__c = app.substring(app.indexof('Zip:') + 5, app.indexof('Telephone Number:'));
          candidate.Home_phone1__c = app.substring(app.indexof('Telephone Number:') + 18, app.indexof('Alternate Telephone Number:'));
          candidate.Personal_Cell_Phone__c = app.substring(app.indexof('Alternate Telephone Number:') + 28, app.indexof('How did you'));
          if (app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2) == 'Other' ) {
              candidate.Source_of_Candidate__c = app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2) + ': ' + 
              app.substring(app.indexof('If other, please specify:') + 26, app.indexof('Most Recent Employer:'));
          }
          else {
             candidate.Source_of_Candidate__c = app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2);
          }
          candidate.Former_Employer_1__c = app.substring(app.indexof('Most Recent Employer:') +22, app.Length());
          
         if (email.fromname == null){
             email.fromname = app.substring(app.indexof('First Name: ') + 12, app.indexof('Last Name:')) + ' ' + app.substring(app.indexof('Last Name: ') + 11, app.indexof('Position'));
         }
         
         if (envelope.fromAddress == null) {
             envelope.fromAddress = app.substring(app.indexof('EMail Address:') + 15, app.indexof('Address1:'));
         }
         
          insert candidate;
          
            if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
              for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Attachment attachment = new Attachment();
                // attach to the newly created Employee record
                attachment.ParentId = candidate.Id;
                attachment.Name = email.binaryAttachments[i].filename;
                attachment.Body = email.binaryAttachments[i].body;
                insert attachment;
              }
            }          
          
          
          return result;
      }
  }

 

  • January 04, 2012
  • Like
  • 0

I am trying to create a simple VF page that renders a PDF from HTML that is passed in by my controller. Using the VF code below, the dynamic HTML renders properly as a regular VF page, but when I add the "renderAs="PDF" to my page tag, only the raw HTML appears in the PDF and not the properly rendered HTML.

 

The following correctly renders the dynamic HTML:

<apex:page controller="trainingLetterPDFController" >
    <apex:outputText value="{!LetterHTMLBody}" escape="false"/>
</apex:page>

 The following renders the page as a PDF showing the raw HTML text:

<apex:page controller="trainingLetterPDFController" renderAs="PDF">
    <apex:outputText value="{!LetterHTMLBody}" escape="false"/>
</apex:page>

 

Any suggestions on how to get this dynamic HTML to render in the PDF?

Thanks!

  • July 09, 2013
  • Like
  • 0

I am a very novice developer and am working on an Email Services class that will parse contact information from applications submitted via our Web site's simple application form. The data is stored in a custom object that we use to track applicants. The email that we receive from the Web site form looks like this:

 

First Name: Joe
Last Name: Test
Position Applying For: Editor/Proofer
EMail Address: test@testemail.com
Address1: 
Address2: 
City: 
State: 
Zip: 
Telephone Number: xxx-xxx-xxxx
Alternate Telephone Number: 
How did you hear about us? Monster.com
If other, please specify: 
Most Recent Employer: Self-Employed

The Email Services code processes this fine when I send this email as a test from my Outlook email client, but when I set up the Web site form to automatically send these applications to the Email Services email address, I receive an email with the following error:

 

"The attached message was sent to the Email Service address <submit_resume@4r0eqtpjrqi4qsx8nryitfmzj.8dnvxeae.c.apex.salesforce.com> but could not be processed because the following error occurred:

 

554 System.StringException: Ending position out of bounds: -1

 

Class.employeeApplication.handleInboundEmail: line 11, column 28 External entry point"

 

What would be different about sending the email from my email address versus having our Web site's form handler send it? My email services code is below for reference:

global class employeeApplication implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          
          SFDC_Employee__c candidate = new SFDC_Employee__c();
          candidate.Employee_Status__c = 'Interested';
          candidate.Initial_Contact_Date__c = System.now().date();
          
          String app = email.plainTextBody;
         
          candidate.Name = app.substring(app.indexof('First Name: ') + 12, app.indexof('Last Name:') - 1) + app.substring(app.indexof('Last Name: ') + 11, app.indexof('Position'));
          candidate.Position__c = app.substring(app.indexof('Position Applying For: ') + 23, app.indexof('EMail Address:'));
          candidate.Email_Address__c = app.substring(app.indexof('EMail Address:') + 15, app.indexof('Address1:'));
          candidate.Home_Address_del__c = app.substring(app.indexof('Address1:') + 10, app.indexof('Address2:')) + app.substring(app.indexof('Address2:') + 10, app.indexof('City:'));
          candidate.Home_City_del__c = app.substring(app.indexof('City:') + 6, app.indexof('State:'));
          candidate.Home_State_del__c = app.substring(app.indexof('State:') + 7, app.indexof('Zip:'));
          candidate.Home_Zip_del__c = app.substring(app.indexof('Zip:') + 5, app.indexof('Telephone Number:'));
          candidate.Home_phone1__c = app.substring(app.indexof('Telephone Number:') + 18, app.indexof('Alternate Telephone Number:'));
          candidate.Personal_Cell_Phone__c = app.substring(app.indexof('Alternate Telephone Number:') + 28, app.indexof('How did you'));
          if (app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2) == 'Other' ) {
              candidate.Source_of_Candidate__c = app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2) + ': ' + 
              app.substring(app.indexof('If other, please specify:') + 26, app.indexof('Most Recent Employer:'));
          }
          else {
             candidate.Source_of_Candidate__c = app.substring(app.indexof('How did you hear about us?') + 27, app.indexof('If other,') - 2);
          }
          candidate.Former_Employer_1__c = app.substring(app.indexof('Most Recent Employer:') +22, app.Length());
          
         if (email.fromname == null){
             email.fromname = app.substring(app.indexof('First Name: ') + 12, app.indexof('Last Name:')) + ' ' + app.substring(app.indexof('Last Name: ') + 11, app.indexof('Position'));
         }
         
         if (envelope.fromAddress == null) {
             envelope.fromAddress = app.substring(app.indexof('EMail Address:') + 15, app.indexof('Address1:'));
         }
         
          insert candidate;
          
            if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
              for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Attachment attachment = new Attachment();
                // attach to the newly created Employee record
                attachment.ParentId = candidate.Id;
                attachment.Name = email.binaryAttachments[i].filename;
                attachment.Body = email.binaryAttachments[i].body;
                insert attachment;
              }
            }          
          
          
          return result;
      }
  }

 

  • January 04, 2012
  • Like
  • 0

Hello.

 

I'm definitely not an expert in SF and am still learning quite a bit, but do have a solid background in programming and data structures.

 

What I'm trying to acomplish is to create a Report that has the Monthly Sales Figures with both a MTD (Month to Date) and a Runrate Value for the month based on the number of fiscal days left in the month.

 

E.g.

RunRate = (MTD Sales / # of completed fiscal days) * Total # of Fiscal Days in Month

 

Within the report builder there are some neat things that calculate using fiscal time periods, but no functions for time at all.  So then I took a look at Formula fields on the object, but can't seem to find much that references the fiscal calendar in SF.  Of course our fiscal calendar does not match the calendar and we use 4-5-4 fiscal months.

 

Any suggestions for acomplishing this, either within the Report directly or by using a Formula Field?

 

Thanks!