Excel File Upload in Salesforce
import { LightningElement, api, wire, track } from 'lwc';
import getPARData from '@salesforce/apex/ExportEPDMDataInCSVCtrl.getPARData';
//import fetchData from '@salesforce/apex/ExportEPDMDataInCSVCtrl.fetchData';
import { createRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import createAttachment from '@salesforce/apex/ExportEPDMDataInCSVCtrl.createAttachment';
export default class PARDetailsLWC extends LightningElement {
@api recordId;
@track parRecord;
@track duplicateHTMLData;
error;
@wire(getPARData, { recordId: '$recordId' })
wiredPARData({ data, error }) {
if (data) {
this.parRecord = data;
this.error = undefined;
console.log('data :: ', JSON.stringify(data));
this.exportExcelData();
//alert(JSON.stringify(this.parRecord));
} else if (error) {
//alert('sds' + this.recordId);
this.error = error;
this.parRecord = undefined;
}
}
@track isTrue = false;
exportExcelData() {
// Prepare a html table
let doc = '<table border="1" style="width: 20%;">';
console.log('1');
//doc += '<style>';
//doc += 'table, th, td {';
//doc += ' border: 1px solid black;';
//doc += ' border-collapse: collapse;';
//doc += '}';
if (this.parRecord) {
doc += '<tr>';
doc += '<th >' + 'ProjectNr' + '</th>';
(this.parRecord.Drawing_Number__c != undefined) ? doc += '<td>' + this.parRecord.Drawing_Number__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Product Line' + '</th>';
(this.parRecord.PAR_Product_Family__c != undefined) ? doc += '<td>' + this.parRecord.PAR_Product_Family__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Market' + '</th>';
(this.parRecord.Opportunity_Name__r.Market_Detail_Codes__c != undefined) ? doc += '<td>' + this.parRecord.Opportunity_Name__r.Market_Detail_Codes__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Customer' + '</th>';
(this.parRecord.Opportunity_Name__r.Account_Name__c != undefined) ? doc += '<td>' + this.parRecord.Opportunity_Name__r.Account_Name__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Country' + '</th>';
(this.parRecord.Opportunity_Name__r.Account_Billing_Country__c != undefined) ? doc += '<td>' + this.parRecord.Opportunity_Name__r.Account_Billing_Country__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Customer Part Number' + '</th>';
(this.parRecord.Customer_Part__c != undefined) ? doc += '<td>' + this.parRecord.Customer_Part__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Similar To PN' + '</th>';
(this.parRecord.Design_similar_to__c != undefined) ? doc += '<td>' + this.parRecord.Design_similar_to__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 Type' + '</th>';
(this.parRecord.Medium_Type_Primary_Internal_Media__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Type_Primary_Internal_Media__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 P Op' + '</th>';
(this.parRecord.Medium_Pressure_Operating__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Pressure_Operating__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 P Lo' + '</th>';
(this.parRecord.Medium_Pressure_Low__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Pressure_Low__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 P Hi' + '</th>';
(this.parRecord.Medium_Pressure_High__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Pressure_High__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Pressure1' + '</th>';
(this.parRecord.PAR_Merket_Segment__c != undefined) ? doc += '<td>' + this.parRecord.PAR_Merket_Segment__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 T Op' + '</th>';
(this.parRecord.Medium_Temperature_Operating__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Temperature_Operating__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 T Lo' + '</th>';
(this.parRecord.Medium_Temperature_Low__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Temperature_Low__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium1 T Hi' + '</th>';
(this.parRecord.Medium_Temperature_High__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Temperature_High__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Temp1' + '</th>';
(this.parRecord.Drawing_Number__c != undefined) ? doc += '<td>' + this.parRecord.Drawing_Number__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Medium2 Type' + '</th>';
(this.parRecord.Medium_Type_Primary_Internal_Media__c != undefined) ? doc += '<td>' + this.parRecord.Medium_Type_Primary_Internal_Media__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Motion Type' + '</th>';
(this.parRecord.Motion_Type__c != undefined) ? doc += '<td>' + this.parRecord.Motion_Type__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Rotational Speed' + '</th>';
(this.parRecord.RPM__c != undefined) ? doc += '<td>' + this.parRecord.RPM__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Direction' + '</th>';
(this.parRecord.Rotation_Direction__c != undefined) ? doc += '<td>' + this.parRecord.Rotation_Direction__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Linear Speed' + '</th>';
(this.parRecord.Drawing_Number__c != undefined) ? doc += '<td>' + this.parRecord.Drawing_Number__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Speed' + '</th>';
(this.parRecord.Stroke_Speed_Unit__c != undefined) ? doc += '<td>' + this.parRecord.Stroke_Speed_Unit__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Stroke Length' + '</th>';
(this.parRecord.Stroke_Length__c != undefined) ? doc += '<td>' + this.parRecord.Stroke_Length__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Length' + '</th>';
(this.parRecord.Stroke_Speed_Unit__c != undefined) ? doc += '<td>' + this.parRecord.Stroke_Speed_Unit__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Leakage Acceptable' + '</th>';
(this.parRecord.Leakage_Acceptable__c != undefined) ? doc += '<td>' + this.parRecord.Leakage_Acceptable__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Leakage' + '</th>';
(this.parRecord.Leakage_Acceptable_UOM__c != undefined) ? doc += '<td>' + this.parRecord.Leakage_Acceptable_UOM__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD' + '</th>';
(this.parRecord.A_Dia__c != undefined) ? doc += '<td>' + this.parRecord.A_Dia__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD Tol 1' + '</th>';
(this.parRecord.A_Diam_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.A_Diam_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD Tol 2' + '</th>';
(this.parRecord.A_Diam_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.A_Diam_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID' + '</th>';
(this.parRecord.B_Dia__c != undefined) ? doc += '<td>' + this.parRecord.B_Dia__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID Tol 1' + '</th>';
(this.parRecord.B_Diam_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.B_Diam_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID Tol 2' + '</th>';
(this.parRecord.B_Diam_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.B_Diam_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Width' + '</th>';
(this.parRecord.Flanged__c != undefined) ? doc += '<td>' + this.parRecord.Flanged__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Width Tol 1' + '</th>';
(this.parRecord.G_Dim_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.G_Dim_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Width Tol 2' + '</th>';
(this.parRecord.G_Dim_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.G_Dim_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Depth' + '</th>';
(this.parRecord.L_ref__c != undefined) ? doc += '<td>' + this.parRecord.L_ref__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Diameter' + '</th>';
(this.parRecord.D_Dia__c != undefined) ? doc += '<td>' + this.parRecord.D_Dia__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Diameter Tol 1' + '</th>';
(this.parRecord.D_Diam_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.D_Diam_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Diameter Tol 2' + '</th>';
(this.parRecord.D_Diam_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.D_Diam_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Width' + '</th>';
(this.parRecord.H_Dim__c != undefined) ? doc += '<td>' + this.parRecord.H_Dim__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Width Tol 1' + '</th>';
(this.parRecord.H_Dim_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.H_Dim_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Flange Width Tol 2' + '</th>';
(this.parRecord.H_Dim_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.H_Dim_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Extrusion Gap' + '</th>';
(this.parRecord.E_Gap__c != undefined) ? doc += '<td>' + this.parRecord.E_Gap__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Gap Tolerance 1' + '</th>';
(this.parRecord.E_Gap_Tol_Minus__c != undefined) ? doc += '<td>' + this.parRecord.E_Gap_Tol_Minus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Gap Tolerance 2' + '</th>';
(this.parRecord.E_Gap_Tol_Plus__c != undefined) ? doc += '<td>' + this.parRecord.E_Gap_Tol_Plus__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Length2' + '</th>';
(this.parRecord.Gland_Axial_Length_G_Units__c != undefined) ? doc += '<td>' + this.parRecord.Gland_Axial_Length_G_Units__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'HW_type' + '</th>';
(this.parRecord.Gland_Type__c != undefined) ? doc += '<td>' + this.parRecord.Gland_Type__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD Material' + '</th>';
(this.parRecord.Drawing_Number__c != undefined) ? doc += '<td>' + this.parRecord.Drawing_Number__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Coating OD' + '</th>';
(this.parRecord.SurfaceA_Coating__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceA_Coating__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD Finish 1' + '</th>';
(this.parRecord.SurfaceA_Finish__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceA_Finish__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Unit Finish1' + '</th>';
(this.parRecord.SurfaceA_Finish_UOM__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceA_Finish_UOM__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'OD Hardness' + '</th>';
(this.parRecord.SurfaceA_Hardness__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceA_Hardness__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID Material' + '</th>';
(this.parRecord.SurfaceB_Material__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceB_Material__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'Coating ID' + '</th>';
(this.parRecord.SurfaceB_Coating__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceB_Coating__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID Finish 1' + '</th>';
(this.parRecord.SurfaceB_Finish__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceB_Finish__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
doc += '<tr>';
doc += '<th >' + 'ID Hardness' + '</th>';
(this.parRecord.SurfaceB_Hardness__c != undefined) ? doc += '<td>' + this.parRecord.SurfaceB_Hardness__c + '</td>' : doc += '<th align="left" >' + '' + '</th>';
doc += '</tr>';
}
// doc += '</tr>';
doc += '</table>';
this.duplicateHTMLData = doc;
//console.log('this.duplicateHTMLData :: ',this.duplicateHTMLData);
//console.log('auto Number :: ',this.parRecord.name);
//console.log('this.parRecord.Opportunity_Name__r.Name :: ',this.parRecord.Opportunity_Name__r.Name);
//alert(this.parRecord.Name);
//alert(this.parRecord.Opportunity_Name__r.Name);
//alert('dvd'+this.duplicateHTMLData);
// fetchData({ htmlData: this.duplicateHTMLData, oppName: this.parRecord.Name, trNumber: this.parRecord.Opportunity_Name__r.Name, recordId: this.parRecord.Id})
// .then(result => {
// //alert(result);
// this.isTrue = true;
// alert(this.isTrue);
// console.log('Apex method response: ', result);
// })
// .catch(error => {
// //alert('Apex');
// console.error('Error calling Apex method: ', error);
// });
//if(this.isTrue == true){
//alert('true--');
/*var element = 'data:application/vnd.ms-excel,' + encodeURIComponent(doc);
let downloadElement = document.createElement('a');
downloadElement.href = element;
downloadElement.target = '_self';
// use .csv as extension on below line if you want to export data as csv
downloadElement.download = this.parRecord.Name +'-'+ this.parRecord.Opportunity_Name__r.Name+'.xls';
document.body.appendChild(downloadElement);
downloadElement.click();
this.removeHeader = false;
console.log('3');
const evt = new ShowToastEvent({
title: 'Download Successful',
message: 'Custom Labels Metadata is downloaded successfully',
variant: 'success',
mode: 'dismissable'
});
this.dispatchEvent(evt);
console.log('4');*/
this.handleExportExcel();
//}
}
//@api parRecord; // Make sure you receive the parRecord as an input property
handleExportExcel() {
// Your code to generate the Excel data (as shown in your question)
// Convert your Excel data to BASE64 encoding
//alert('call method');
const fileContents = btoa(this.duplicateHTMLData);
const fileTitle = this.parRecord.Name + '-' + this.parRecord.Opportunity_Name__r.Name + '.xls';
//alert(fileTitle);
this.uploadFile(fileTitle, fileContents);
}
async uploadFile(fileTitle, fileContents) {
try {
const attachmentId = await createAttachment({
parentId: this.parRecord.Id,
name: fileTitle,
body: fileContents,
contentType: 'application/vnd.ms-excel',
});
// File uploaded successfully
const toastEvent = new ShowToastEvent({
title: 'File Uploaded',
message: 'The Excel file has been uploaded as an attachment.',
variant: 'success',
});
this.dispatchEvent(toastEvent);
} catch (error) {
// Handle any errors
console.error('Error uploading file:', error);
const toastEvent = new ShowToastEvent({
title: 'Error Uploading File',
message: 'An error occurred while uploading the file.',
variant: 'error',
});
this.dispatchEvent(toastEvent);
}
}
}
------------------------------------------------------
<template>
<!-- <button class="slds-button slds-button_neutral" onclick={exportExcelData} style="background-color: #102a89;">
<span class="slds-truncate" style="color: #ffffff;">Download</span>
<lightning-icon icon-name="action:download" size="x-small" style="background-color: inherit;"></lightning-icon>
</button> -->
</template>
public with sharing class ExportEPDMDataInCSVCtrl {
@AuraEnabled(cacheable=true)
public static CES_PAR__c getPARData(String recordId) {
/*List<CES_PAR__c> listOfRec = [SELECT id, Drawing_Number__c, PAR_Product_Family__c, Opportunity_Name__r.Market_Detail_Codes__c, Opportunity_Name__r.Account_Billing_Country__c, Opportunity_Name__r.Account_Name__c, Customer_Part__c, Design_similar_to__c, Medium_Type_Primary_Internal_Media__c, Medium_Pressure_Operating__c, Medium_Pressure_Low__c, Medium_Pressure_High__c, PAR_Merket_Segment__c, Medium_Temperature_Operating__c, Medium_Temperature_Low__c, Medium_Temperature_High__c, Temperatur_Units__c, Motion_Type__c, Rotation_Direction__c, Stroke_Speed__c, Stroke_Speed_Unit__c, Stroke_Length__c, Leakage_Acceptable__c, Leakage_Acceptable_UOM__c, A_Dia__c, A_Diam_Tol_Minus__c, A_Diam_Tol_Plus__c, B_Dia__c, B_Diam_Tol_Minus__c, B_Diam_Tol_Plus__c, Flanged__c, G_Dim_Tol_Minus__c, G_Dim_Tol_Plus__c, L_ref__c, D_Dia__c, D_Diam_Tol_Minus__c, D_Diam_Tol_Plus__c, H_Dim__c, H_Dim_Tol_Minus__c, H_Dim_Tol_Plus__c, E_Gap__c, E_Gap_Tol_Minus__c, E_Gap_Tol_Plus__c, Gland_Type__c, Gland_Axial_Length_G_Units__c, SurfaceA_Material__c, SurfaceA_Coating__c, SurfaceA_Finish__c, SurfaceA_Finish_UOM__c, SurfaceA_Hardness__c, SurfaceB_Material__c, SurfaceB_Coating__c, SurfaceB_Finish__c, SurfaceB_Hardness__c, RPM__c FROM CES_PAR__c WHERE Id = 'a3z7h000000boi3AAA' LIMIT 1];
List<CES_PAR__c> listOfNew = New List<CES_PAR__c>();
String nullValues = null;
for(CES_PAR__c cesLst : listOfRec){
if(cesLst != null){
listOfNew.add(cesLst);
}else{
listOfNew.add(String.valueOf());
}
}*/
return [SELECT id,Name,Opportunity_Name__r.Name, Drawing_Number__c, PAR_Product_Family__c, Opportunity_Name__r.Market_Detail_Codes__c, Opportunity_Name__r.Account_Billing_Country__c, Opportunity_Name__r.Account_Name__c, Customer_Part__c, Design_similar_to__c, Medium_Type_Primary_Internal_Media__c, Medium_Pressure_Operating__c, Medium_Pressure_Low__c, Medium_Pressure_High__c, PAR_Merket_Segment__c, Medium_Temperature_Operating__c, Medium_Temperature_Low__c, Medium_Temperature_High__c, Temperatur_Units__c, Motion_Type__c, Rotation_Direction__c, Stroke_Speed__c, Stroke_Speed_Unit__c, Stroke_Length__c, Leakage_Acceptable__c, Leakage_Acceptable_UOM__c, A_Dia__c, A_Diam_Tol_Minus__c, A_Diam_Tol_Plus__c, B_Dia__c, B_Diam_Tol_Minus__c, B_Diam_Tol_Plus__c, Flanged__c, G_Dim_Tol_Minus__c, G_Dim_Tol_Plus__c, L_ref__c, D_Dia__c, D_Diam_Tol_Minus__c, D_Diam_Tol_Plus__c, H_Dim__c, H_Dim_Tol_Minus__c, H_Dim_Tol_Plus__c, E_Gap__c, E_Gap_Tol_Minus__c, E_Gap_Tol_Plus__c, Gland_Type__c, Gland_Axial_Length_G_Units__c, SurfaceA_Material__c, SurfaceA_Coating__c, SurfaceA_Finish__c, SurfaceA_Finish_UOM__c, SurfaceA_Hardness__c, SurfaceB_Material__c, SurfaceB_Coating__c, SurfaceB_Finish__c, SurfaceB_Hardness__c, RPM__c FROM CES_PAR__c WHERE Id =:recordId];
}
@AuraEnabled
public static String fetchData(String htmlData, String oppName, String trNumber, String recordId) {
//System.debug('param1 '+ param1);
//param1 = '<table style="width: 20%;"><style>table, th, td { border: 1px solid black; border-collapse: collapse;}<tr><th bgcolor="c6c6c6">ProjectNr</th><tr><th bgcolor="c6c6c6">Product Line</th><tr><th bgcolor="c6c6c6">Market</th><tr><th bgcolor="c6c6c6">Customer</th><tr><th bgcolor="c6c6c6">Country</th><tr><th bgcolor="c6c6c6">Customer Part Number</th><tr><th bgcolor="c6c6c6">Similar To PN</th><tr><th bgcolor="c6c6c6">Medium1 Type</th><tr><th bgcolor="c6c6c6">Medium1 P Op</th><tr><th bgcolor="c6c6c6">Medium1 P Lo</th><tr><th bgcolor="c6c6c6">Medium1 P Hi</th><tr><th bgcolor="c6c6c6">Unit Pressure1</th><tr><th bgcolor="c6c6c6">Medium1 T Op</th><tr><th bgcolor="c6c6c6">Medium1 T Lo</th><tr><th bgcolor="c6c6c6">Medium1 T Hi</th><tr><th bgcolor="c6c6c6">Unit Temp1</th><tr><th bgcolor="c6c6c6">Medium2 Type</th><tr><th bgcolor="c6c6c6">Motion Type</th><tr><th bgcolor="c6c6c6">Rotational Speed</th><tr><th bgcolor="c6c6c6">Direction</th><tr><th bgcolor="c6c6c6">Linear Speed</th><tr><th bgcolor="c6c6c6">Unit Speed</th><tr><th bgcolor="c6c6c6">Stroke Length</th><tr><th bgcolor="c6c6c6">Unit Length</th><tr><th bgcolor="c6c6c6">Leakage Acceptable</th><tr><th bgcolor="c6c6c6">Unit Leakage</th><tr><th bgcolor="c6c6c6">OD</th><tr><th bgcolor="c6c6c6">OD Tol 1</th><tr><th bgcolor="c6c6c6">OD Tol 2</th><tr><th bgcolor="c6c6c6">ID</th><tr><th bgcolor="c6c6c6">ID Tol 1</th><tr><th bgcolor="c6c6c6">ID Tol 2</th><tr><th bgcolor="c6c6c6">Width</th><tr><th bgcolor="c6c6c6">Width Tol 1</th><tr><th bgcolor="c6c6c6">Width Tol 2</th><tr><th bgcolor="c6c6c6">Depth</th><tr><th bgcolor="c6c6c6">Flange Diameter</th><tr><th bgcolor="c6c6c6">Flange Diameter Tol 1</th><tr><th bgcolor="c6c6c6">Flange Diameter Tol 2</th><tr><th bgcolor="c6c6c6">Flange Width</th><tr><th bgcolor="c6c6c6">Flange Width Tol 1</th><tr><th bgcolor="c6c6c6">Flange Width Tol 2</th><tr><th bgcolor="c6c6c6">Extrusion Gap</th><tr><th bgcolor="c6c6c6">Gap Tolerance 1</th><tr><th bgcolor="c6c6c6">Gap Tolerance 2</th><tr><th bgcolor="c6c6c6">Unit Length2</th><tr><th bgcolor="c6c6c6">HW_type</th><tr><th bgcolor="c6c6c6">OD Material</th><tr><th bgcolor="c6c6c6">Coating OD</th><tr><th bgcolor="c6c6c6">OD Finish 1</th><tr><th bgcolor="c6c6c6">Unit Finish1</th><tr><th bgcolor="c6c6c6">OD Hardness</th><tr><th bgcolor="c6c6c6">ID Material</th><tr><th bgcolor="c6c6c6">Coating ID</th><tr><th bgcolor="c6c6c6">ID Finish 1</th><tr><th bgcolor="c6c6c6">ID Hardness</th></tr></table>';
System.debug(htmlData);
System.debug(oppName);
System.debug(trNumber);
System.debug(recordId);
ContentVersion contentVersion = new ContentVersion();
contentVersion.Title = trNumber+' - '+oppName;
contentVersion.PathOnClient = trNumber+' - '+oppName+'.xlsx'; // You can choose a filename
contentVersion.VersionData = Blob.valueOf(htmlData);
contentVersion.FirstPublishLocationId = recordId;
insert contentVersion;
System.debug(contentVersion);
return htmlData;
}
/*public static List<CES_PAR__c> performAction(String recordId) {
System.debug('msg '+ recordId);
List<CES_PAR__c> listOfRec = [Select id, Drawing_Number__c, PAR_Product_Family__c,Customer_Part__c,Design_similar_to__c,Medium_Type_Primary_Internal_Media__c,Medium_Pressure_Operating__c,Medium_Pressure_Low__c,Medium_Pressure_High__c,PAR_Merket_Segment__c,Medium_Temperature_Operating__c,Medium_Temperature_Low__c,
Medium_Temperature_High__c,Temperatur_Units__c,Motion_Type__c,Rotation_Direction__c,Stroke_Speed__c,Stroke_Speed_Unit__c,Stroke_Length__c,Leakage_Acceptable__c,Leakage_Acceptable_UOM__c,A_Dia__c,A_Diam_Tol_Minus__c ,A_Diam_Tol_Plus__c, B_Dia__c,B_Diam_Tol_Minus__c, B_Diam_Tol_Plus__c,Flanged__c,G_Dim_Tol_Minus__c,G_Dim_Tol_Plus__c,L_ref__c,D_Dia__c,D_Diam_Tol_Minus__c,D_Diam_Tol_Plus__c,H_Dim__c,H_Dim_Tol_Minus__c,H_Dim_Tol_Plus__c,E_Gap__c,E_Gap_Tol_Minus__c,E_Gap_Tol_Plus__c ,Gland_Type__c ,Gland_Axial_Length_G_Units__c,SurfaceA_Material__c,SurfaceA_Coating__c,SurfaceA_Finish__c, SurfaceA_Finish_UOM__c,SurfaceA_Hardness__c,SurfaceB_Material__c,SurfaceB_Coating__c,SurfaceB_Finish__c,SurfaceB_Hardness__c from CES_PAR__c
where id =: recordId limit 1];
System.debug('msglistOfRec '+ listOfRec);
if(!listOfRec.isEmpty()){
return listOfRec;
}else{
return New List<CES_PAR__c>();
}
}*/
}
Comments
Post a Comment