You need to sign in to do that
Don't have an account?
Raghavendra M 13
Apex Class:
public with sharing class CreateWorkOrderRecord
{
/**
* Create a new Work Order Record
*
* @param WorkOrder Work Order Work Order record to be inserted
*
*/
@AuraEnabled
public static String createRecord(WorkOrder workorder)
{
try
{
System.debug('CreateWorkOrderRecord::createRecord::workorder'+workorder);
if(workorder!= null)
insert workorder;
}
catch (Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
return null;
}
return null;
}
@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="CreateWorkOrderRecord"
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="workorder" type="WorkOrder" default="{'sobjectType': 'WorkOrder',
'Account__c': '',
'Contact__c': '',
'Opportunity__c': '',
'Priority': '',
'StartDate': '',
'Status': '',
'Number_of_Weeks__c': '',
'Visit_Frequency__c': '',
}"/><br/>
<div>
<table>
<tr>
<td>
<h2 style="font-weight:bold;font-size:12px;margin-left:5%">New Work Order Edit</h2>
<h1 style="font-weight:bold;font-size:18px;margin-left:5%">New Work Order</h1>
</td>
</tr>
</table>
</div><br/>
<center>
<div class="col-md-4 text-center">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
</div>
</center><br/>
<div class="slds-box" style="background:rgb(0, 161, 223);font-weight:bold;font-size:15pt;">
<p>WorkOrder Information</p>
</div>
<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 width="45%">
<table>
<tr>
<td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
</tr>
<tr>
<td><c:customLookup objectAPIName="contact" IconName="standard:contact" label="Contact" selectedRecord="{!v.selectedLookUpRecord1}"/></td>
</tr>
<tr>
<td><c:customLookup objectAPIName="opportunity" IconName="standard:opportunity" label="Opportunity" selectedRecord="{!v.selectedLookUpRecord2}"/></td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Priority</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Priority}">
<ui:inputSelectOption text="Low"/>
<ui:inputSelectOption text="Medium"/>
<ui:inputSelectOption text="High"/>
<ui:inputSelectOption text="Critical"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
<td width="10%"></td>
<td width="45%">
<table>
<tr>
<td>
<label>StartDate</label>
<ui:inputDate displayDatePicker="true" value="{!v.workorder.StartDate}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Status</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Status}">
<ui:inputSelectOption text="New"/>
<ui:inputSelectOption text="In Progress"/>
<ui:inputSelectOption text="On Hold"/>
<ui:inputSelectOption text="Completed"/>
<ui:inputSelectOption text="Closed"/>
<ui:inputSelectOption text="Cannot Complete"/>
<ui:inputSelectOption text="Canceled"/>
</ui:inputSelect>
</td>
</tr>
</div>
<tr>
<td>
<p class="title">Number of Visits</p>
<ui:inputNumber value="{!v.workorder.Number_of_Weeks__c}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Visit Frequency</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Visit_Frequency__c}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Daily"/>
<ui:inputSelectOption text="Weekly"/>
<ui:inputSelectOption text="Monthly"/>
<ui:inputSelectOption text="Custom Schedule"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
</tr>
</thead>
</table>
<br/>
<center>
<div class="col-md-4 text-center">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
</div>
</center>
<br/>
</div>
</div>
</aura:component>
Controller:
({
create : function(component, event, helper) {
console.log('Create record');
//getting the workorder information
var workorder = component.get("v.workorder");
workorder.Account__c = null;
workorder.Contact__c = null;
workorder.Opportunity__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){
workorder.Account__c = component.get("v.selectedLookUpRecord").Id;
}
if(component.get("v.selectedLookUpRecord1").Id != undefined){
workorder.Contact__c = component.get("v.selectedLookUpRecord1").Id;
}
if(component.get("v.selectedLookUpRecord2").Id != undefined){
workorder.Opportunity__c = component.get("v.selectedLookUpRecord2").Id;
}
//Calling the Apex Function
var action = component.get("c.createRecord");
//Setting the Apex Parameter
action.setParams({
workorder : workorder
});
//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 newWorkorder = {'sobjectType': 'WorkOrder',
'Account__c': '',
'Contact__c': '',
'Opportunity__c': '',
'Priority': '',
'StartDate': '',
'Status': '',
'Number_of_Weeks__c': '',
'Visit_Frequency__c': '',
};
//resetting the Values in the form
component.set("v.workorder",newWorkorder);
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) {
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"));
}
})
Can any one solve my below Problem?
Apex Class:
public with sharing class CreateWorkOrderRecord
{
/**
* Create a new Work Order Record
*
* @param WorkOrder Work Order Work Order record to be inserted
*
*/
@AuraEnabled
public static String createRecord(WorkOrder workorder)
{
try
{
System.debug('CreateWorkOrderRecord::createRecord::workorder'+workorder);
if(workorder!= null)
insert workorder;
}
catch (Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
return null;
}
return null;
}
@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="CreateWorkOrderRecord"
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="workorder" type="WorkOrder" default="{'sobjectType': 'WorkOrder',
'Account__c': '',
'Contact__c': '',
'Opportunity__c': '',
'Priority': '',
'StartDate': '',
'Status': '',
'Number_of_Weeks__c': '',
'Visit_Frequency__c': '',
}"/><br/>
<div>
<table>
<tr>
<td>
<h2 style="font-weight:bold;font-size:12px;margin-left:5%">New Work Order Edit</h2>
<h1 style="font-weight:bold;font-size:18px;margin-left:5%">New Work Order</h1>
</td>
</tr>
</table>
</div><br/>
<center>
<div class="col-md-4 text-center">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
</div>
</center><br/>
<div class="slds-box" style="background:rgb(0, 161, 223);font-weight:bold;font-size:15pt;">
<p>WorkOrder Information</p>
</div>
<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 width="45%">
<table>
<tr>
<td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
</tr>
<tr>
<td><c:customLookup objectAPIName="contact" IconName="standard:contact" label="Contact" selectedRecord="{!v.selectedLookUpRecord1}"/></td>
</tr>
<tr>
<td><c:customLookup objectAPIName="opportunity" IconName="standard:opportunity" label="Opportunity" selectedRecord="{!v.selectedLookUpRecord2}"/></td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Priority</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Priority}">
<ui:inputSelectOption text="Low"/>
<ui:inputSelectOption text="Medium"/>
<ui:inputSelectOption text="High"/>
<ui:inputSelectOption text="Critical"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
<td width="10%"></td>
<td width="45%">
<table>
<tr>
<td>
<label>StartDate</label>
<ui:inputDate displayDatePicker="true" value="{!v.workorder.StartDate}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Status</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Status}">
<ui:inputSelectOption text="New"/>
<ui:inputSelectOption text="In Progress"/>
<ui:inputSelectOption text="On Hold"/>
<ui:inputSelectOption text="Completed"/>
<ui:inputSelectOption text="Closed"/>
<ui:inputSelectOption text="Cannot Complete"/>
<ui:inputSelectOption text="Canceled"/>
</ui:inputSelect>
</td>
</tr>
</div>
<tr>
<td>
<p class="title">Number of Visits</p>
<ui:inputNumber value="{!v.workorder.Number_of_Weeks__c}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Visit Frequency</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.workorder.Visit_Frequency__c}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Daily"/>
<ui:inputSelectOption text="Weekly"/>
<ui:inputSelectOption text="Monthly"/>
<ui:inputSelectOption text="Custom Schedule"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
</tr>
</thead>
</table>
<br/>
<center>
<div class="col-md-4 text-center">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
</div>
</center>
<br/>
</div>
</div>
</aura:component>
Controller:
({
create : function(component, event, helper) {
console.log('Create record');
//getting the workorder information
var workorder = component.get("v.workorder");
workorder.Account__c = null;
workorder.Contact__c = null;
workorder.Opportunity__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){
workorder.Account__c = component.get("v.selectedLookUpRecord").Id;
}
if(component.get("v.selectedLookUpRecord1").Id != undefined){
workorder.Contact__c = component.get("v.selectedLookUpRecord1").Id;
}
if(component.get("v.selectedLookUpRecord2").Id != undefined){
workorder.Opportunity__c = component.get("v.selectedLookUpRecord2").Id;
}
//Calling the Apex Function
var action = component.get("c.createRecord");
//Setting the Apex Parameter
action.setParams({
workorder : workorder
});
//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 newWorkorder = {'sobjectType': 'WorkOrder',
'Account__c': '',
'Contact__c': '',
'Opportunity__c': '',
'Priority': '',
'StartDate': '',
'Status': '',
'Number_of_Weeks__c': '',
'Visit_Frequency__c': '',
};
//resetting the Values in the form
component.set("v.workorder",newWorkorder);
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) {
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"));
}
})
Thanks
http://sfdcmonkey.com
All Answers
Please check this below line.... there is no aura id 'singleResult' in component.
var resultCmp = cmp.find("singleResult");
If this is help for you make it Best Ans
Thanks
Jayabalaji
Thanks
http://sfdcmonkey.com