加载资源失败:服务器响应状态为500(服务器错误)-Salesforce中发生跨源错误时严格源代码
要求是从一个外部网址,我们将得到一个PDF,并必须下载该PDF(VFPage) Apex代码:加载资源失败:服务器响应状态为500(服务器错误)-Salesforce中发生跨源错误时严格源代码,salesforce,apex,visualforce,Salesforce,Apex,Visualforce,要求是从一个外部网址,我们将得到一个PDF,并必须下载该PDF(VFPage) Apex代码: HTTPResponse response = Continuation.getResponse(reqLabel); if((response.getStatusCode() != 200 && response.getBody().LEFT(10) != '"fault"') || (response.getSt
HTTPResponse response = Continuation.getResponse(reqLabel);
if((response.getStatusCode() != 200 && response.getBody().LEFT(10) != '"fault"') || (response.getStatusCode() == 200 && response.getBody().LEFT(10).contains('"fault"'))) {
faultObj = PartnerInvoiceServiceUtility.parsePDFResponse(response.getBody());
System.debug('faultobj '+faultobj);
}
if(faultObj == null) {
Map<String,object> lst_JsonParse = (Map<String,object>)Json.deserializeUntyped(response.getBody());
string invoicePDFURL = (string)(lst_JsonParse.get('invoicePdfUrl'));
system.debug('invoicePDFURL> ' + invoicePDFURL);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(invoicePDFURL);
req.setMethod('GET');
req.setHeader('Content-Type', 'application/pdf');
//Now Send HTTP Request
system.debug('retFile req ' + req);
HttpResponse res = h.send(req);
system.debug('retFile response ' + res);
system.debug('retFile response body ' + res.getBody());
invoicePDF = EncodingUtil.base64Encode(res.getBodyAsBlob()); // Passing this to VF Page
system.debug('invoicePDF > ' + invoicePDF);
pdfGenerated = true; //Passing this to VF Page
HTTPResponse response=Continuation.getResponse(reqLabel);
if((response.getStatusCode()!=200&&response.getBody().LEFT(10)!='fault')| |(response.getStatusCode()==200&&response.getBody().LEFT(10).包含('fault')){
faultObj=PartnerInvoiceServiceUtility.parsePDFResponse(response.getBody());
系统调试('faultobj'+faultobj);
}
if(faultObj==null){
Map lst_JsonParse=(Map)Json.deserializeUntyped(response.getBody());
字符串invoicePDFURL=(字符串)(lst_JsonParse.get('invoicePDFURL');
系统调试('invoicePDFURL>'+invoicePDFURL);
Http h=新的Http();
HttpRequest req=新的HttpRequest();
请求setEndpoint(InvoicePdfur);
请求setMethod('GET');
请求setHeader('Content-Type','application/pdf');
//现在发送HTTP请求
系统调试(“retFile req”+req);
HttpResponse res=h.send(请求);
system.debug('retFile response'+res);
debug('retFile response body'+res.getBody());
invoicePDF=EncodingUtil.base64Encode(res.getBodyAsBlob());//将此传递给VF页面
调试('invoicePDF>'+invoicePDF);
pdfGenerated=true;//将其传递给VF页面
VF页面
<script>
console.log('In Dummy Panel...');
var isPDFGenergated = {!pdfGenerated};
if(isPDFGenergated){
debugger;
console.log('PDF Genrated Flag: True');
var invoiceBlob = '{!invoicePDF}';
exportActualFileToPDF2('download');
$jq('#pdfError').hide();
console.log('hiding spinner now');
hideSpinner();
}
if('{!system_pdferrormessage}'!= null && '{!system_pdferrormessage}' !='')
{
console.log('Exception: System Error ' + '{!system_pdferrormessage}');
$jq('#pdfError').show();
$jq('#pdfError').html('{!system_pdferrormessage}');
}
</script>