You need to sign in to do that
Don't have an account?
Thulasi Reddys
Cannot get Work order Lookup in Lightning Component?
Apex Class:
Component:
public with sharing class OpportunitySaveCtrl { /** * Create a new Opportunity Record * * @param WorkOrder Opportunity Opportunity record to be inserted * */ public static list<opportunity> opportunity{get;set;} @AuraEnabled public static List<String> sssPickvalues{get;set;} @AuraEnabled public static List<String> cctypePickvalues{get;set;} @AuraEnabled public static String createRecord(Opportunity opportunity) { try { System.debug('OpportunitySaveCtrl::createRecord::opportunity'+opportunity); if(opportunity!= null) insert opportunity; } catch (Exception ex) { } return null; } public static List<String> getServicesspickvalue() { sssPickvalues = new List<String>(); Sobject ss = new opportunity(); String sssfield='LeadSource'; sssPickvalues.add('--None--'); sssPickvalues.addall(getselectOptions(ss,sssfield)); return sssPickvalues; } @AuraEnabled public static List<String> getcctypepickvalue() { cctypePickvalues= new List<String>(); Sobject ss = new opportunity(); String sssfield='StageName'; cctypePickvalues.add('--None--'); cctypePickvalues.addall(getselectOptions(ss,sssfield)); return cctypePickvalues; } @AuraEnabled public static List <String> getselectOptions(sObject objObject, string fld) { List <String> allOpts = new list <String>(); Schema.sObjectType objType = objObject.getSObjectType(); // Get the object type of the SObject. Schema.DescribeSObjectResult objDescribe = objType.getDescribe(); // Describe the SObject using its object type. Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); // Get a map of fields for the SObject List <Schema.PicklistEntry> values = fieldMap.get(fld).getDescribe().getPickListValues(); // Get the list of picklist values for this field. for(Schema.PicklistEntry a: values) allOpts.add(a.getValue()); // Add these values to the selectoption list. allOpts.sort(); return allOpts; } }
Component:
<aura:component controller="OpportunitySaveCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" > <!-- Include Static Resource--> <ltng:require styles="/resource/bootstrap1/css/bootstrap.min.css" scripts="/resource/bootstrap1/js/jquery.js,/resource/bootstrap/js/bootstrap.min.js"/> <!-- Define Attribute--> <aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/> <aura:attribute name="selectedLookUpRecord1" type="sObject" default="{}"/> <aura:attribute name="selectedLookUpRecord2" type="sObject" default="{}"/> <aura:attribute name="number" type="integer"/> <aura:attribute name="myText" type="String"/> <aura:attribute name="opportunity" type="Opportunity" default="{'sobjectType': 'Opportunity', 'Name': '', 'Account__c': '', 'Primary_Contact__c': '', 'Work_Order__c': '', 'LeadSource': '', 'StageName' : '', 'CloseDate': '', 'Priority__c' : '', }"/><br/> <div style="background-color:white;padding:10pt;border-radius:5px;"> <div> <table> <tr> <td> <h2 style="font-weight:bold;font-size:12px;margin-left:5%">New Opportunity Edit</h2> <h1 style="font-weight:bold;font-size:18px;margin-left:5%">New Opportunity</h1> </td> </tr> </table> </div><br/> <center> <!--<div class="col-md-4 text-center"> <lightning:button variant="brand" label="Save" onclick="{!c.create}"/> </div>--> <lightning:button variant="brand" label="Save" onclick="{!c.create}"/> <lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/> </center><br/> <!-- <div class="slds-box" style="background:rgb(0, 161, 223);font-weight:bold;font-size:15pt;"> <p>Opportunity Information</p> </div>--> <h3 class="slds-section__title slds-theme_shade"> <span class="slds-truncate slds-p-horizontal_small" title="Address Information">Opportunity Information</span> </h3> <div class="slds-grid slds-gutters"> <div class="slds-col" style="width:500px;"> <table class="slds-table slds-table--bordered slds-table--cell-buffer"> <thead> <tr> <td> <table> <tr> <td><p class="title">Opportunity Name</p> <ui:inputText value="{!v.opportunity.Name}"/></td> </tr> <tr> <td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account Name" selectedRecord="{!v.selectedLookUpRecord}"/></td> </tr> <tr> <td><c:customLookup objectAPIName="WorkOrder" IconName="standard:workOrder" label="Work Order" selectedRecord="{!v.selectedLookUpRecord2}"/></td> </tr> <tr> <td><c:customLookup objectAPIName="contact" IconName="standard:contact" label="Primary Contact" selectedRecord="{!v.selectedLookUpRecord1}"/></td> </tr> <div class="form-group"> <tr> <td> <p class="title">Lead Source</p> <ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opportunity.LeadSource}"> <ui:inputSelectOption text="Web"/> <ui:inputSelectOption text="External Referral"/> <ui:inputSelectOption text="Trade Show"/> <ui:inputSelectOption text="Public Relations"/> </ui:inputSelect> </td> </tr> </div> </table> </td> <td> <table> <tr> <td> <p class="title">Stage</p> <ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opportunity.StageName}"> <ui:inputSelectOption text="Closed Won"/> <ui:inputSelectOption text="Closed Lost"/> <ui:inputSelectOption text="Patriot Suggestion"/> <ui:inputSelectOption text="Agree to Proceed"/> </ui:inputSelect> </td> </tr> <tr> <td> <label>Close Date</label> <ui:inputDate aura:id="mySelectedDate" displayDatePicker="true" value="{!v.opportunity.CloseDate}"/> </td> </tr> <div class="form-group"> <tr> <td> <p class="title">Priority</p> <ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opportunity.Priority__c}"> <ui:inputSelectOption text="Low"/> <ui:inputSelectOption text="Medium"/> <ui:inputSelectOption text="High"/> <ui:inputSelectOption text="Critical"/> </ui:inputSelect> </td> </tr> </div> </table> </td> </tr> </thead> </table> </div> </div> </div> </aura:component>Controller:
({ create : function(component, event, helper) { console.log('Create record'); //getting the candidate information var opportunity = component.get("v.opportunity"); opportunity.Account__c = null; opportunity.Primary_Contact__c = null; opportunity.Work_Order__c = null; /***************Validation if($A.util.isEmpty(workorder.Opportunity__c) || $A.util.isUndefined(workorder.Opportunity__c)){ alert('Account Name is Required'); return; }*************************************************/ if(component.get("v.selectedLookUpRecord").Id != undefined){ opportunity.Account__c = component.get("v.selectedLookUpRecord").Id; } if(component.get("v.selectedLookUpRecord1").Id != undefined){ opportunity.Primary_Contact__c = component.get("v.selectedLookUpRecord1").Id; } if(component.get("v.selectedLookUpRecord2").Id != undefined){ opportunity.Work_Order__c = component.get("v.selectedLookUpRecord2").Id; } //Calling the Apex Function var action = component.get("c.createRecord"); //Setting the Apex Parameter action.setParams({ opportunity : opportunity }); //Setting the Callback action.setCallback(this,function(a){ //get the response state var state = a.getState(); //check if result is successfull if(state == "SUCCESS"){ //Reset Form var newOpportunity = {'sobjectType': 'Opportunity', 'Name': '', 'Account__c': '', 'Primary_Contact__c': '', 'Work_Order__c': '', 'StageName' : '', 'CloseDate': '', 'Priority__c' : '', }; //resetting the Values in the form component.set("v.opportunity",newOpportunity); alert('Record is Created Successfully'); } else if(state == "ERROR"){ alert('Error in calling server side action'); } }); //adds the server-side action to the queue $A.enqueueAction(action); }, onSingleSelectChange: function(cmp,event,helper) { var selectCmpValue = event.getSource().get("v.value"); }, /***onSingleSelectChange: function(cmp) { var selectCmp = cmp.find("InputSelectSingle"); var resultCmp = cmp.find("singleResult"); resultCmp.set("v.value", selectCmp.get("v.value")); },***************/ onChange: function(cmp) { var dynamicCmp = cmp.find("InputSelectDynamic"); var resultCmp = cmp.find("dynamicResult"); resultCmp.set("v.value", dynamicCmp.get("v.value")); } })
SOQL: select id, Name from WorkOrder where Name LIKE 'Test%' order by createdDate DESC limit 5
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_workorder.htm
Can you access the field Name of WorkOrder ? <c:customLookup objectAPIName="WorkOrder" IconName="standard:workOrder" label="Work Order" selectedRecord="{!v.selectedLookUpRecord2}"/></td>
http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
http://sfdcmonkey.com/2017/01/07/custom-lookup-lightning-component/
I tried to use this custom lookup component but I prefered the Strike Lookup http://www.lightningstrike.io/#!/strikeLookup
Or Philippe Ozil's lookup: https://github.com/pozil/sfdc-ui-lookup
Now there is a standard Lex component <lightning:inputField> (Spring 18')