You need to sign in to do that
Don't have an account?
Paul Bénard
pdf attachment dynamic error
Hi Guys,
I have a strange problem when I am attaching a Pdf to an object.
this is my code:
the id of the object relance in order to attach the pdf to this object :
Id parentId = relanceFromList.id;
Now I am creating the pdf:
PageReference pageRef = page.VFP_PDFCreate; //controller which create the page/pdf
pageRef.getParameters().put('id',parentId); //put the id of my object in order to do some operation in another controller
And I put in the attachment the pdf:
Attachment attach = new Attachment();
attach.ParentId = parentId;
Blob body;
try
{
body = pageRef.getContent();
}
catch (VisualforceException e)
{
body = Blob.valueOf('Error : ' + e);
}
attach.Body = body;
attach.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + '-' + parentId + '.pdf';
attach.IsPrivate = false;
List_Attach.add(attach);
}
...
upsert(List_Attach);
The strange thing is that when I am putting an Id manually: Id parentId = '01pb0000003AfqY' <= example
I can acces to the attachment from the page https://eu2.salesforce.com/01pb0000003AfqY in the related lists.
=>But If I am putting the Id of my object relance dynamically(how it is describe in this code) I can see the attachment in the related list of my object relance but when I click on the link the error "Failed to load the PDF files" appears.
If you have any idea, please inform me.
If the given informationsare not sufficients, tell me also.
Thank you in advance
p.b.
I have a strange problem when I am attaching a Pdf to an object.
this is my code:
the id of the object relance in order to attach the pdf to this object :
Id parentId = relanceFromList.id;
Now I am creating the pdf:
PageReference pageRef = page.VFP_PDFCreate; //controller which create the page/pdf
pageRef.getParameters().put('id',parentId); //put the id of my object in order to do some operation in another controller
And I put in the attachment the pdf:
Attachment attach = new Attachment();
attach.ParentId = parentId;
Blob body;
try
{
body = pageRef.getContent();
}
catch (VisualforceException e)
{
body = Blob.valueOf('Error : ' + e);
}
attach.Body = body;
attach.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + '-' + parentId + '.pdf';
attach.IsPrivate = false;
List_Attach.add(attach);
}
...
upsert(List_Attach);
The strange thing is that when I am putting an Id manually: Id parentId = '01pb0000003AfqY' <= example
I can acces to the attachment from the page https://eu2.salesforce.com/01pb0000003AfqY in the related lists.
=>But If I am putting the Id of my object relance dynamically(how it is describe in this code) I can see the attachment in the related list of my object relance but when I click on the link the error "Failed to load the PDF files" appears.
If you have any idea, please inform me.
If the given informationsare not sufficients, tell me also.
Thank you in advance
p.b.
Please refer following blog for entire code for this requirement:
http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/
Thank you for the link but I knew it. I have done my code according to it.
Any suggestion about where the bug could come?
Thank you
I am trying in the same function to :
- create a register relance
- create an attachment with the info from the register just created inside.
But it's in the same function and when I am going in the pdf controller :
PageReference pageRef = page.VFP_PDFCreate; //controller which create the page/pdf
pageRef.getParameters().put('id',parentId); //put the id of my object in order to do some operation in another controller
the controller do not get the Id of the register relance. And in my function I am creating several relance and I wanted to create in same time the attachment. Even if I have insert the relance, if I do not get out the primary controller (it seems) the other controller does not get the ID.
If you had encontourned this problem let me know.
Thank you guys,