• Heber
  • 0 Points
  • Member since 2014
  • Solution Engineer
  • SirsiDynix

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2

Hello, I've made some lightning components and vfpage that will allow my users to select select, preview and save pdf templates from the Quote object. I now have the need to use the same functionality on other objects in my org. However, I don't quite see how I can do it without making new lightning components. The main challenge is in how to use the <force:recordData> dynamically....I think that is what I want to do. For example, if the component could recognize that it was on a Quote or an Invoice or some other custom object then my server side controller could get the appropriate template options and the rest will be easy. The part that I don't see is how to make force:recordData work with multiple objects. 

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" controller="pdfDI_SelectTemplate2_Controller">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="selectedTemplate" type="String"/>
    <aura:attribute name="templateOptions" type="List"/>
    <aura:attribute name="record_Q" type="Quote"/> 
    <force:recordData aura:id="recordLoader_Q"
    <lightning:layout multipleRows="false">
        <lightning:layoutItem size="6">
        	<div class="row">
        		<!--<p class="title">Select Template:</p>-->
    			<ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}">
        			<option value="">...Select a Template...</option>
            		<aura:iteration items="{!v.templateOptions}" var="t_opt" indexVar="key">
                		<ui:inputSelectOption text="{!t_opt.value}" label="{!t_opt.key}"/>
    	<lightning:layoutItem size="6">
        <div class="slds-p-left_large">
    	 	<lightning:button label="Save PDF" title="Save PDF" onclick="{! c.savePDF }"/>
	<div class="slds-p-top_large">
        <p>PDF Preview:</p>
    	<c:pdfDI_DisplayTemplate selectedTemplate="{!v.selectedTemplate}" recordId2="{!v.recordId}"/>
        // Load template options from Salesforce
    doInit: function(cmp, event, helper) {
        // Create the action
        var action = cmp.get("c.getTemplateOptions");
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var custs = [];
                var conts = response.getReturnValue();
                for(var key in conts) {
                    custs.push({value:conts[key], key:key});
            else {
                console.log("Failed with state: " + state);
        // Send action off to be executed
    onSingleSelectChange: function(cmp) {
        var selectCmp = cmp.find("InputSelectSingle");
        cmp.set("v.selectedTemplate", selectCmp.get("v.value"));
    savePDF : function(cmp, event, helper) {
        var recordId = cmp.get("v.recordId");
        var selectedTemplate = cmp.get("v.selectedTemplate");
        var qName = cmp.get("v.record_Q.Name");
        var pdfName = selectedTemplate;
        var vfPage = '/apex/pdfDI_QuoteStandard2'; //really should pull this from child component.
        var action = cmp.get("c.savePDF_Quote");
            "vfPage": vfPage, 
            "recordId" : recordId, 
            "selectedTemplate" : selectedTemplate, 
            "pdfName" : qName
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('Attachment saved successfully');
            else if (state === "INCOMPLETE") {
                // do something
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                    } else {
                        console.log("Unknown error");
I'm using the salesforce upsert component, but the field lookup field is getting empty. The field in the related object is an external ID, since I am using a product code and not the salesforce id.
The csv is apparently correct.
Who do you have any idea?

User-added image
Conf. Upsert
User-added image

Conf csv
User-added image

Related object
User-added image

User-added image