You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Created Pdf is not working with flow and apex class
Hello,
I want to create a pdf through a flow. I made a flow with an apex action that creates a pdf in files. The problem I have is, that when I click on the pdf i do not see the text template but an error message that something worked wrong. Could you tell me what to chamge to make it work?
The apex class:
public class ContactContentVersion {
@InvocableMethod(label = 'Create ContentVersion')
public static FlowOutput[] createFile(FlowInput[] inputs) {
ContentVersion[] createfiles= new ContentVersion[]{};
for(FlowInput input : inputs) {
ContentVersion file = new ContentVersion();
String data;
if(input.fileExtension == 'PDF') {
data = input.data.escapeXML().replace('\r\n', '<br>').replace('\r', '<br>').replace('\n', '<br>');
} else {
data = input.data;
}
file.Title = input.title;
file.PathOnClient = file.Title + '.' + input.fileExtension;
file.VersionData = Blob.valueOf(data);
if(String.isNotEmpty(input.parentId)) {
file.FirstPublishLocationId = input.parentId;
}
createfiles.add(file);
}
insert createfiles;
FlowOutput[] outputs = new FlowOutput[]{};
for(ContentVersion cv : [SELECT Id,ContentDocumentId FROM ContentVersion WHERE Id IN :createfiles]) {
FlowOutput output = new FlowOutput();
output.contentDocumentId = cv.ContentDocumentId;
outputs.add(output);
}
return outputs;
}
public class FlowInput {
@InvocableVariable(label='ContentVersion Title' required='true')
public String title;
@InvocableVariable(label='ContentVersion Data' required='true')
public String data;
@InvocableVariable(label='ContentVersion Extension' required='true')
public String fileExtension;
@InvocableVariable(label='Related Record ID')
public String parentId;
}
public class FlowOutput {
@InvocableVariable(label='ContentDocument Id')
public String contentDocumentId;
}
}
I want to create a pdf through a flow. I made a flow with an apex action that creates a pdf in files. The problem I have is, that when I click on the pdf i do not see the text template but an error message that something worked wrong. Could you tell me what to chamge to make it work?
The apex class:
public class ContactContentVersion {
@InvocableMethod(label = 'Create ContentVersion')
public static FlowOutput[] createFile(FlowInput[] inputs) {
ContentVersion[] createfiles= new ContentVersion[]{};
for(FlowInput input : inputs) {
ContentVersion file = new ContentVersion();
String data;
if(input.fileExtension == 'PDF') {
data = input.data.escapeXML().replace('\r\n', '<br>').replace('\r', '<br>').replace('\n', '<br>');
} else {
data = input.data;
}
file.Title = input.title;
file.PathOnClient = file.Title + '.' + input.fileExtension;
file.VersionData = Blob.valueOf(data);
if(String.isNotEmpty(input.parentId)) {
file.FirstPublishLocationId = input.parentId;
}
createfiles.add(file);
}
insert createfiles;
FlowOutput[] outputs = new FlowOutput[]{};
for(ContentVersion cv : [SELECT Id,ContentDocumentId FROM ContentVersion WHERE Id IN :createfiles]) {
FlowOutput output = new FlowOutput();
output.contentDocumentId = cv.ContentDocumentId;
outputs.add(output);
}
return outputs;
}
public class FlowInput {
@InvocableVariable(label='ContentVersion Title' required='true')
public String title;
@InvocableVariable(label='ContentVersion Data' required='true')
public String data;
@InvocableVariable(label='ContentVersion Extension' required='true')
public String fileExtension;
@InvocableVariable(label='Related Record ID')
public String parentId;
}
public class FlowOutput {
@InvocableVariable(label='ContentDocument Id')
public String contentDocumentId;
}
}