function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
S.AjS.Aj 

Broken URL

Hi there,


In our Dev Instance we are generating PDF documents for certain custom objects, and in these pages have images placed in them, they are either accessed by adding in the documents folder, which is set to be accessible to everyone and externally available  too.   And sometimes accessing external images from other websites by adding them in remote settings, and both of the ways work fine.

 

However  in our  test instance the image appears to be broken.

 

The image URL is passed as string from the controller to the VF page:

 

<apex:image url="{!Logo_URL}" width="25%"/>



Im not sure how to handle this.

 

Any work around is greatly appreciated.

 

Regards and thanks in advance

S.AJ

sekharasekhara
Hi,

You have to give Path for Image.
Image in Static Resource or in Documents.
S.AjS.Aj

Hi,

 

The by path you mean the address, right? If so it is saved in a url field in one of the custom objects and is accessed thru the controller's page 

 

Thanks and Regards

S.Aj

sekharasekhara

can u ping me the link syntax u kept 

sekharasekhara
Hi,

I got Image as Lease Work.
S.AjS.Aj

that's the image saved in the documents:

the URL is passed from the controller

 

This is the part where URL is accessed from the controller class

public string Logo_URL;

public AircraftController () {

Id id = ApexPages.currentPage().getParameters().get('id');

Logo_URL = LeaseWareUtils.getLogoURL();
System.debug('----------- LEASEWARE -------- LeaseWareUtils:getLogoURL Returning URL'+Logo_URL);



public string getLogo_URL()
{

return Logo_URL;
}

 

}

 

LeaseWareUtils is a utility class and this is the part 

 

  public static String getLogoURL()
    {
      String url='';
      Lessor__c[] lsr = getLessor();
      Integer i=0; 
      for (Lessor__c ls:lsr)
      {
        i++;
        System.debug('----------- LEASEWARE -------- LeaseWareUtils:getLogoURL i is '+i);
        
        if (i==1) // these is a ghost item in this array that is returned, so return value in 1 position
           url = ls.Lease_Logo__c; 
      }
      System.debug('----------- LEASEWARE -------- LeaseWareUtils:getLogoURL Returning URL'+url);
      
      return url;
    }
    public static Lessor__c[] getLessor()
    {
      Lessor__c[] thisLsr;
        //find the Lessor details
        thisLsr = [select id, name, Lease_Logo__c from Lessor__c];
        System.debug('----------- LEASEWARE -------- LeaseWareUtils: Lessor is '+thisLsr);

        return thisLsr;
    }

 

 

However as I mentioned it works fine in the dev instance but in the test instance the image is broken 

 

S.AjS.Aj
That way the URL is going to be hard coded, which is not we need, the image need to be changed according to the customer requirement.
Shiv ShankarShiv Shankar

Can you post contrller and VF Page code.

S.AjS.Aj

this is the controller class:

 

public with sharing class ClaimFormController {

private final Aircraft_Eligible_Event_Invoice__c Aee_In;
private final Aircraft_Eligible_Event__c Aee;
private final Aircraft__c parentAC;
public string Logo_URL;

public ID AeeIn_Id {get;set;}
private ID Aee_Id;
private ID parentAC_ID;
public String email {get;set;}
public String sub {get;set;}
public String ebody {get;set;}


public ClaimFormController() {

Logo_URL = LeaseWareUtils.getLogoURL();

List<Aircraft_Eligible_Event_Invoice__c> AeeIn_list = [select id, Aircraft_Eligible_Event__c, Invoice_Amount__c, Invoice_Date__c,
Invoice_Type__c, MR_20_Month_C_Check__c, MR_APU__c,MR_Engine_1__c,MR_Engine_1_LLP__c,MR_Engine_2__c,
MR_Engine_2_LLP__c, MR_Engine_3__c,MR_Engine_3_LLP__c,MR_Engine_4__c,MR_Engine_4_LLP__c,
MR_Heavy_Maintenance_1_Airframe__c,MR_Heavy_Maintenance_2_Airframe__c,
MR_Landing_Gear__c, Name
from Aircraft_Eligible_Event_Invoice__c where id = :ApexPages.currentPage().getParameters().get('id')];


if (AeeIn_list.size() > 0)
{
Aee_In = AeeIn_list.get(0);
AeeIn_Id = Aee_In.id;

Aee_Id = Aee_In.Aircraft_Eligible_Event__c;
}

List<Aircraft_Eligible_Event__c> Aee_list = [select id, Aircraft__c, Balance_Amount__c, Initial_Claim_Amount__c,
CSN__c, Event_Type__c, Comments__c, Start_Date__c,End_Date__c,
Invoiced_Amount__c, TSN_N__c, Name
from Aircraft_Eligible_Event__c where id = : Aee_Id];

if (Aee_list.size() > 0)
{
Aee = Aee_list.get(0);
Aee_Id = Aee.id;

parentAC_ID = Aee.Aircraft__c;
}

List<Aircraft__c> Ac_spec = [select id,Logo__c, Aircraft_Type__c, Assigned_To__c, Country_Of_Registration__c,MSN_Number__c,
CSN__c, Cycles_Since_Last_C_Check__c, Lease__c,Approach_Landing_Cat__c,
Number_of_engines__c, Registration_Number__c,ETOPS__c,Line_Num__c,
Time_Remaining_To_Check__c,TSN__c,Time_Since_Last_C_Check__c
from Aircraft__c where id = :parentAC_ID];

if (Ac_spec.size() > 0)
{
parentAC = Ac_spec.get(0);
}



}


public Aircraft_Eligible_Event_Invoice__c getAee_In() {
return Aee_In;
}
public Aircraft_Eligible_Event__c getAee() {
return Aee;
}

public Aircraft__c getparentAC() {
return parentAC;
}

public string getLogo_URL()
{
return Logo_URL;
}


public PageReference sendPdf() {

PageReference pdf = Page.ClaimFormPDF;
// add parent id to the parameters for standardcontroller
pdf.getParameters().put('id',Aee_In.id);

// the contents of the attachment from the pdf
Blob body;

// returns the output of the page as a PDF
body = pdf.getContent();



Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('ClaimFormPDF.pdf');
attach.setInline(false);
attach.Body = body;

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setToAddresses(new String[] { email });
mail.setSubject(sub);
mail.setplainTextBody(ebody);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });

// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with Claim Form sent to '+email));

return null;

}

}

 

this is the VF page:

 

<apex:page controller="ClaimFormController" renderAs="pdf">

<apex:stylesheet value="{!$Resource.CssStyleSheet}"/>
<table width="100%">
<tr width="50%" align="right">
<td width="50%" align="right">
<apex:image url="{!Logo_URL}" width="25%"/>
</td>
</tr>

<tr width="50%">
<td width="50%" align="left">
<apex:panelGrid columns="1" width="25%" styleClass="infobox">
<apex:outputText value="Claim Form # : {!Aee_In.Name}" />
<apex:outputText value=" Invoice Date : {!Aee_In.Invoice_Date__c}">

</apex:outputText>
</apex:panelGrid>
</td>

</tr>

</table>

<br></br>

<h1>Customer Information</h1>
<hr width="200"></hr>
<table width="100%">
<tr>
<td ><b>Customer: </b></td>
<td >{!parentAC.Assigned_To__c}</td>

<td ><b>Aircraft Type </b></td>
<td >{!parentAC.Aircraft_Type__c}</td>

</tr>

<tr>

<td><b>Invoice Type</b></td>
<td>{!Aee_In.Invoice_Type__c}</td>
<td ><b>MSN</b></td>
<td >{!parentAC.MSN_Number__c}</td>
</tr>

</table>
<br></br>
<br></br>


</apex:page>

 

and this is a part of the utility class where the URL is originally read:

 

public static String getLogoURL()
{
String url='';
Lessor__c[] lsr = getLessor();
Integer i=0;
for (Lessor__c ls:lsr)
{
i++;
System.debug('----------- LEASEWARE -------- LeaseWareUtils:getLogoURL i is '+i);

if (i==1) // these is a ghost item in this array that is returned, so return value in 1 position
url = ls.Lease_Logo__c;
}
System.debug('----------- LEASEWARE -------- LeaseWareUtils:getLogoURL Returning URL'+url);

return url;
}
public static Lessor__c[] getLessor()
{
Lessor__c[] thisLsr;
//find the Lessor details
thisLsr = [select id, name, Lease_Logo__c from Lessor__c];
System.debug('----------- LEASEWARE -------- LeaseWareUtils: Lessor is '+thisLsr);

return thisLsr;
}