• Laura Boyd 18
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
Hi,

Due to an intergration we are trying to run between an old third party system and Salesforce, I need to split the value of the street field in Salesforce into multiple formula fields. 

Based on another post, I have this working with the below code if the user enters a comma at the end of the line. Ideally though, I want it to do the split based on the "end of the line". Is there some sort of end of line character that I could replace the comma with in my forumla?
 
LEFT(BillingStreet, FIND(",",BillingStreet)-1)
Mid(TRIM(BillingStreet), FIND(",",TRIM(BillingStreet))+2, FIND(",",TRIM(BillingStreet),FIND(",",TRIM(BillingStreet))+2) - FIND(",",TRIM(BillingStreet)) -2)


Thanks,
Laura

Hi,

To set the background:

I have a VF page which is triggered from a lightning action button on an object called Purchase_Order__c
The button directs to the VF page called SendEmailDialog_VF which calls the controller SendEmailDialog_Controller. The controller functionality is to send an email with a PDF attachment. The PDF is generated there and then using another VF page as a template

The functionality is working perfectly if I leave the filename for the PDF in the controller as a static value,but the requirement is to include a variable as part of the file name. I worked out how to do this using apex param value but are now experiencing the following situation:

1) If I use just Apex Param Value as part of the command button then it just passes the variable across as 'null'
2) If i add the the ReRender option to the command button functionality, as people recommend to do, the email sends and the PDF has the right filename BUT the PDF file gives an error about being corrupt when opened.

Any guidance would be appreciated.

VF Page (SendEmailDialog_VF)

<apex:page standardController="Purchase_Order__c" extensions="SendPDFbyEmail" showQuickActionVfHeader="false">

      

      <h1 style="font-size:16px">Send Email</h1>

      <p style="font-size:12px">Complete the below form to send the PDF by email</p>

     

      <apex:form >

      <apex:pageBlock >

      <apex:pageBlockSection columns="3">

      <apex:outputLabel style="font-size: 12px" for="Email Address" value="Email Address:">&nbsp; </apex:outputLabel>

      <apex:inputText size="50" maxlength="50" id="EmailAddress" value="{!emailAddress}" required="true"/><br></br>

      <apex:outputLabel style="font-size: 12px" for="Subject" value="Subject:">&nbsp; </apex:outputLabel>

      <apex:inputText size="50" maxlength="50" id="Subject" value="{!eSubject}" required="true"/><br></br>

      <apex:outputLabel style="font-size: 12px" for="Body" value="Body">:</apex:outputLabel>

      <apex:inputTextarea rows="10" html-maxlength="1024" style="width:99%" id="Body" value="{!eBody}" required="true"/><br></br>



      <apex:commandButton value="Send" action="{!SendEmail}" rerender="hiddenBlock">

      <apex:param name="POName" value="{!Purchase_Order__c.Name}" assignTo="{!POName}"/>

      </apex:commandButton>

      <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>

  

      </apex:pageBlockSection>

      </apex:pageBlock>

      </apex:form>  

</apex:page>
 

VF Controller (SendEmailDialog_Controller)
 

public with sharing class SendPDFbyEmail {



public SendPDFbyEmail (ApexPages.StandardController controller){

}



//Set variable values

public String POName {get;set;}

public String EmailAddress {get;set;}

public String eSubject{get;set;}

public String eBody{get;set;}





//Start mail process and set criteria for PDF

public PageReference SendEmail() {



Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();

PageReference pdfGeneration=Page.Purchase_Order_PDF;

pdfGeneration.SetRedirect(true);

Blob b=pdfGeneration.getContent();



//Create attachment and set criteria

Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();

attach.setFileName(POName+': '+DateTime.now().format('ddMMyyyy')+'.pdf');



attach.setBody(b);



    email.SetSubject(eSubject);

    email.SetPlainTextBody(eBody);

    email.setToAddresses(new String[] { EmailAddress });

    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});



    

//Now Sending the Email

Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

    

    return null;

    

}
}
Hi

I have a controller (shown below) which generates a PDF and sends it by email.

I am setting the file name in the line of:
attach.setFileName('POFile.pdf');

All I want to do is add todays date to the the filename which I have tried as:
attach.setFileName('POFile{!Today()}.pdf');

All is does is bolt the text of "{!Today()} to end of the filename rather than inserting the date.

Any ideas where I am going wrong?

 
public with sharing class SendPDFbyEmail {

public SendPDFbyEmail (ApexPages.StandardController controller) {
}

//Set variable values
public String EmailAddress {get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}



//Start mail process and set criteria for PDF
public PageReference SendEmail() {

Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
PageReference pdfGeneration=Page.Purchase_Order_PDF;
pdfGeneration.SetRedirect(true);
Blob b=pdfGeneration.getContent();

//Create attachment and set criteria
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setFileName('PoFile"{!Today()}".pdf');
attach.setBody(b);

    email.SetSubject(eSubject);
    email.SetPlainTextBody(eBody);
    email.setToAddresses(new String[] { EmailAddress });
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});

    
//Now Sending the Email
Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
    return null;
    
    }
    }


 
Hi,

I have a VF page which displays values from multiple objects (Purchase_Order__c (parent), Items (child of parent), Supplier (lookup from purchase order) etc.

I have written a controller which generates a PDF based on the above template and emails it to the specified email address. This works fine.

The issue I have is that I have used the addfields method to provide access to the Purchase Order object fields which works perfectly but I now need to add in access to the other objects fields. I presumed I could just repeat the addfields method put keep getting error of: You cannot call addFields after you've already loaded the data. This must be the first thing in your constructor 
 
Controller:

public class SendEmail{

public SendEmail(ApexPages.StandardController controller) {

    controller.addFields(new List<String>{'Name', 'Annual_Contract__c', 'Date_Raised__c', 'Total__c', 'Justification__c'});
    Purchase_Order__c po=(Purchase_Order__c) controller.getRecord();

}

//Set variable values
public String EmailAddress {get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}


//Start mail process and set criteria for PDF
public PageReference SendEmail() {

Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
PageReference pdfGeneration=Page.Purchase_Order_PDF;
pdfGeneration.SetRedirect(true);
Blob b=pdfGeneration.getContent();

//Create attachment and set criteria
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setFileName('AttachmentEmailFile.pdf');
attach.setBody(b);

    email.SetSubject(eSubject);
    email.SetPlainTextBody(eBody);
    email.setToAddresses(new String[] { EmailAddress });
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});
    
    
//Now Sending the Email
Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
    return null;
    
    }
    }

VF Page: 

<apex:page standardController="Purchase_Order__c" renderAs="pdf" applyBodyTag="false">
    <head>
        <style type="text/css" media="print">

            @page {    
            @bottom-center {
                    content: "Company Address: {!$Organization.Name}, {!$Organization.Street}, {!$Organization.City}, {!$Organization.PostalCode}, {!$Organization.Phone}";
                    font-size: 10pt;
            }
            }
            
            * {
            margin: 0px;
            padding: 0px;
            font-family: Arial Unicode MS;
            font-size: 10pt;
            }
         
            div.logoheader {
            background: url("{!$Resource.Logo}") no-repeat left;
            margin-top: 15px;
            height: 130px;
            width: 300px;
            position: running(header);
            }
            
            div.poblock {
            float:right;
            text-align: right;
            font-size: 10pt;
            margin-top: 15px;
            }
            
            
            .tableHead {
            border-width: 2px 0px 2px 0px;
            border-color: #000;
            border-style: solid;
            text-align: center;
            padding: 5px;
            background-color: #eee;
            margin-top: 60px;
            
            
            } 
            
            
            .tablebody {
            border-width: 1px;
            border-color: #000;
            border-style: solid;
            text-align: center;
            padding: 5px
            
            
            }     
            
            div.footer {
            display: block;
            padding: 5px;
            position: running(footer);
            text-align: center;
            margin-bottom: 15px;
            font-size: 10pt;

            }

            
            #totalCost {
            margin-top: 15px;
            margin-right: 25px;
            text-align: right;
            
            }
            
            #totalCostLabel {
            font-weight: bold;
            margin-right: 65px;
            text-align: right;

            }
            
        </style>
    </head>
    
<table width="100%" style="margin-top: 5px;">

    <tr width="100%">
        <td width="30%" align="left">
        <apex:image id="theImage" value="{!$Resource.Logo}" width="200px"/>
        </td>
        
        <td width="30%" align="center">
        </td>
        
        
        <td width="40%" align="right">
                <p style="text-align:left; font-size: 30pt; font-weight: bold; vertical-align:top;">Purchase Order</p>
                <div class="poblock">
                <apex:panelGrid columns="3">
                <apex:outputLabel value="PO Name: "/><apex:OutputText value="{!Purchase_Order__c.Name}"/><br></br>
                <apex:outputlabel value="Date Requested: "/><apex:outputText value="{0,date,dd'/'MM'/'yyyy}"><apex:param value="{!Purchase_Order__c.Date_Raised__c}"/></apex:outputText><br></br>
                <apex:outputlabel value="Requester: "/><apex:outputText value="{!Purchase_Order__c.Requester__r.FirstName&" "&Purchase_Order__c.Requester__r.LastName}"/><br></br>
                </apex:panelGrid>
                </div>
             
        </td>
        </tr>

</table> 
  

<table align="center" width="100%" style="margin-top:80px;">
    <tr>
        <th id="SPDetails" style="border-style: solid; background-color: #eee; padding: 2px; border-width: 3px;">Supplier Details</th>
        <th id="Blank"></th>
        <th id="ShipTo" style="border-style: solid; background-color: #eee; padding: 2px; border-width: 3px;">Ship To</th>
    </tr>
    <tr width="100%">
        <td width="25%" align="left" style="border-style: solid; border-width: 1px; padding: 3px">
            <apex:panelGrid columns="1">
                <apex:outputText value="{!Purchase_Order__c.Supplier_Name__r.Name}" />
                <apex:outputText value="{!Purchase_Order__c.Supplier_Name__r.Street__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Supplier_Name__r.City__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Supplier_Name__r.County__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Supplier_Name__r.Postcode__c}"/>
            </apex:panelGrid>
        </td>
        
        <td width="40%" align="center"></td>
        
        <td width="25%" style="border-style: solid; border-width: 1px; padding: 3px;">
            <apex:panelGrid columns="1">
                <apex:outputText value="{!Purchase_Order__c.Delivery_Contact__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Delivery_Addresses__r.Name}"/>
                <apex:outputText value="{!Purchase_Order__c.Delivery_Addresses__r.City__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Delivery_Addresses__r.County__c}"/>
                <apex:outputText value="{!Purchase_Order__c.Delivery_Addresses__r.Postcode__c}"/>
            </apex:panelGrid>
        </td>

</tr>
</table>

<apex:pageBlock >
    <apex:pageBlockSection columns="1">
        <apex:pageBlockTable value="{!Purchase_Order__c.items__r}" var="item" columnsWidth="16%,16%,16%,16%,16%,16%" headerClass="tableHead" style="margin-top: 45px;">
            <apex:column value="{!item.Name}" styleClass="tablebody"/>
            <apex:column value="{!item.Budget_Year__c}" styleClass="tablebody"/>
            <apex:column value="{!item.Department_Budget__c}" styleClass="tablebody"/>
            <apex:column value="{!item.Product__c}" styleClass="tablebody"/>
            <apex:column value="{!item.Quantity__c}" styleClass="tablebody"/>
            <apex:column value="{!item.Cost__c}" styleClass="tablebody"/>         
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock> 

<div id="totalCost"><span id="totalCostLabel">{!$ObjectType.Purchase_Order__c.Fields.Total__c.Label}:</span> <apex:outputField value="{!Purchase_Order__c.Total__c}"/></div>

<table align="left" width="100%" style="border-style: solid; border-width: 1px; padding: 1.5px; margin-top: 35px;">
<tr>
<td>
<apex:panelGrid columns="1">
     <apex:outputLabel value="Comments" rendered="{!IF(Purchase_Order__c.Justification__c <> "", true, false)}"/>
     <apex:outputText value="{!Purchase_Order__c.Justification__c}" rendered="{!IF(Purchase_Order__c.Justification__c <> "", true, false)}"/>
</apex:panelGrid>
</td>
</tr>
</table>


</apex:page>
Hi,

Bear with, I am new to visualforce ;-)

I have two custom objects - Purchase_Order__c, which has a child object called Items. They have a master detail relationship.

I have built a controller to create a PDF attachement and send an email, which works when using a very basic VF page for the PDF. I have now updated the VF page which involves displaying fields on from both Purchase Order and Items object - but when trying to run the process it gives the error of "SObject row was retrieved via SOQL without querying the requested field: Purchase_Order__c.Items__r"

Reading through the forums, it seems that I need to give access to these fields in the controller but I have no idea how.

A copy of my controller is below, any advice would be appreciated.


public class EmailSend {

    public EmailSend(ApexPages.StandardController controller) {

}

//Set variable values
public String EmailAddress {get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}


//Start mail process and set criteria for PDF
public PageReference SendEmail() {

Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
PageReference pdfGeneration=Page.Purchase_Order_PDF;
pdfGeneration.SetRedirect(true);
Blob b=pdfGeneration.getContent();

//Create attachment and set criteria
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setFileName('AttachmentEmailFile.pdf');
attach.setBody(b);

    email.SetSubject(eSubject);
    email.SetPlainTextBody(eBody);
    email.setToAddresses(new String[] { EmailAddress });
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});
    
    
//Now Sending the Email
Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
    return null;
    
    }
    }

 
Hi,

I am reasonably new to Visualforce so bear with.

I have a lightning action on a custom object (called PO Records). This lightning action calls a VF page, which in turn has an action / extension in it which generates and saves a PDF to the custom object.

This part works fine, but when the button is pressed I get a blank dialog box which appears until the action is finished. 

Any ideas how to stop this white dialog box happening?

Thanks, 

Laura

Hi,

To set the background:

I have a VF page which is triggered from a lightning action button on an object called Purchase_Order__c
The button directs to the VF page called SendEmailDialog_VF which calls the controller SendEmailDialog_Controller. The controller functionality is to send an email with a PDF attachment. The PDF is generated there and then using another VF page as a template

The functionality is working perfectly if I leave the filename for the PDF in the controller as a static value,but the requirement is to include a variable as part of the file name. I worked out how to do this using apex param value but are now experiencing the following situation:

1) If I use just Apex Param Value as part of the command button then it just passes the variable across as 'null'
2) If i add the the ReRender option to the command button functionality, as people recommend to do, the email sends and the PDF has the right filename BUT the PDF file gives an error about being corrupt when opened.

Any guidance would be appreciated.

VF Page (SendEmailDialog_VF)

<apex:page standardController="Purchase_Order__c" extensions="SendPDFbyEmail" showQuickActionVfHeader="false">

      

      <h1 style="font-size:16px">Send Email</h1>

      <p style="font-size:12px">Complete the below form to send the PDF by email</p>

     

      <apex:form >

      <apex:pageBlock >

      <apex:pageBlockSection columns="3">

      <apex:outputLabel style="font-size: 12px" for="Email Address" value="Email Address:">&nbsp; </apex:outputLabel>

      <apex:inputText size="50" maxlength="50" id="EmailAddress" value="{!emailAddress}" required="true"/><br></br>

      <apex:outputLabel style="font-size: 12px" for="Subject" value="Subject:">&nbsp; </apex:outputLabel>

      <apex:inputText size="50" maxlength="50" id="Subject" value="{!eSubject}" required="true"/><br></br>

      <apex:outputLabel style="font-size: 12px" for="Body" value="Body">:</apex:outputLabel>

      <apex:inputTextarea rows="10" html-maxlength="1024" style="width:99%" id="Body" value="{!eBody}" required="true"/><br></br>



      <apex:commandButton value="Send" action="{!SendEmail}" rerender="hiddenBlock">

      <apex:param name="POName" value="{!Purchase_Order__c.Name}" assignTo="{!POName}"/>

      </apex:commandButton>

      <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>

  

      </apex:pageBlockSection>

      </apex:pageBlock>

      </apex:form>  

</apex:page>
 

VF Controller (SendEmailDialog_Controller)
 

public with sharing class SendPDFbyEmail {



public SendPDFbyEmail (ApexPages.StandardController controller){

}



//Set variable values

public String POName {get;set;}

public String EmailAddress {get;set;}

public String eSubject{get;set;}

public String eBody{get;set;}





//Start mail process and set criteria for PDF

public PageReference SendEmail() {



Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();

PageReference pdfGeneration=Page.Purchase_Order_PDF;

pdfGeneration.SetRedirect(true);

Blob b=pdfGeneration.getContent();



//Create attachment and set criteria

Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();

attach.setFileName(POName+': '+DateTime.now().format('ddMMyyyy')+'.pdf');



attach.setBody(b);



    email.SetSubject(eSubject);

    email.SetPlainTextBody(eBody);

    email.setToAddresses(new String[] { EmailAddress });

    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});



    

//Now Sending the Email

Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

    

    return null;

    

}
}
Hi

I have a controller (shown below) which generates a PDF and sends it by email.

I am setting the file name in the line of:
attach.setFileName('POFile.pdf');

All I want to do is add todays date to the the filename which I have tried as:
attach.setFileName('POFile{!Today()}.pdf');

All is does is bolt the text of "{!Today()} to end of the filename rather than inserting the date.

Any ideas where I am going wrong?

 
public with sharing class SendPDFbyEmail {

public SendPDFbyEmail (ApexPages.StandardController controller) {
}

//Set variable values
public String EmailAddress {get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}



//Start mail process and set criteria for PDF
public PageReference SendEmail() {

Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
PageReference pdfGeneration=Page.Purchase_Order_PDF;
pdfGeneration.SetRedirect(true);
Blob b=pdfGeneration.getContent();

//Create attachment and set criteria
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setFileName('PoFile"{!Today()}".pdf');
attach.setBody(b);

    email.SetSubject(eSubject);
    email.SetPlainTextBody(eBody);
    email.setToAddresses(new String[] { EmailAddress });
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});

    
//Now Sending the Email
Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
    return null;
    
    }
    }


 
Hi,

Bear with, I am new to visualforce ;-)

I have two custom objects - Purchase_Order__c, which has a child object called Items. They have a master detail relationship.

I have built a controller to create a PDF attachement and send an email, which works when using a very basic VF page for the PDF. I have now updated the VF page which involves displaying fields on from both Purchase Order and Items object - but when trying to run the process it gives the error of "SObject row was retrieved via SOQL without querying the requested field: Purchase_Order__c.Items__r"

Reading through the forums, it seems that I need to give access to these fields in the controller but I have no idea how.

A copy of my controller is below, any advice would be appreciated.


public class EmailSend {

    public EmailSend(ApexPages.StandardController controller) {

}

//Set variable values
public String EmailAddress {get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}


//Start mail process and set criteria for PDF
public PageReference SendEmail() {

Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
PageReference pdfGeneration=Page.Purchase_Order_PDF;
pdfGeneration.SetRedirect(true);
Blob b=pdfGeneration.getContent();

//Create attachment and set criteria
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setFileName('AttachmentEmailFile.pdf');
attach.setBody(b);

    email.SetSubject(eSubject);
    email.SetPlainTextBody(eBody);
    email.setToAddresses(new String[] { EmailAddress });
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach});
    
    
//Now Sending the Email
Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
    return null;
    
    }
    }