We have a problem in my org related to the locale and the creation of the Quote PDF.
We have 2 offices ("Europe" and "America") for the Quote object, specified in the Office (Office__c) picklist field.
We have an ETL using REST API that at some point modifies the Quote and this triggers a Flow that creates a standar PDF calling an Apex class.
The problem we have is that the PDF is always created with the locale of the API User, which is: "Spanish (Spain)".
We need that the Quote PDF is created with the locale related to the Office: · If Europe -> Spanish (Spain) · If America -> English (United States)
How can we achive that?
Edit:
This is how I am generating the Quote PDF via apex:
Public class generateQuotePdfDocument{
@InvocableMethod
public static void quotesIdToPDF(List<Id> quoteIds)
{
if(!quoteIds.isEmpty() && quoteIds.size() > 0) {
for(Id quoteId :quoteIds) {
insertQuoteTemplate(quoteId);
}
}
}
@future(callout=true)
public static void insertQuoteTemplate(String quoteId) {
//Get the Quote Template Id from Custom Settings
String quoteTemplateId = Label.QuoteTemplateId;
Quote q = [SELECT Id FROM Quote WHERE Id = :quoteId];
//Construct de Quote URL to generate PDF
String quoteUrl = '/quote/quoteTemplateDataViewer.apexp?id='+quoteId+'&headerHeight=19&footerHeight=10&summlid='+quoteTemplateId;
//call the quote url
PageReference pageRef = new PageReference(quoteUrl);
//get the quotePdf
Blob quoteBlob;
if(Test.isRunningTest()) {
quoteBlob = Blob.valueOf('Generate Pdf');
} else {
quoteBlob = pageRef.getContentAsPDF();
}
//Initialze the QuoteDocument to hold the quote pdf for insertion
QuoteDocument quoteDoc = new QuoteDocument();
quoteDoc.Document = quoteBlob;
quoteDoc.QuoteId = quoteId;
//List variable to get all the Quote Documents
List<QuoteDocument> lstQuoteDoc = new List<QuoteDocument>();
lstQuoteDoc.add(quoteDoc);
if(!lstQuoteDoc.isEmpty() && lstQuoteDoc.size() > 0) {
Database.insert(lstQuoteDoc);
}
}
}
Note: The languange of the PDF doesn't matter. The important thing is we need to change the locale to show correctly Currencies delimiters, based on the Quote Office custom picklist field and using the same User.
Thanks!