You need to sign in to do that
Don't have an account?
Sai Subhash 6
Apex Class:
public with sharing class CreateOpportunityRecord
{
/**
* Create a new Opportunity Record
*
* @param Opportunity record to be inserted
*
*/
@AuraEnabled
public static String createRecord(Opportunity opp)
{
try
{
System.debug('CreateOpportunityRecord::createRecord::opp'+opp);
if(opp!= null)
insert opp;
}
catch (Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
return null;
}
return null;
}
}
Component:
<aura:component controller="CreateOpportunityRecord"
implements="lightning:actionOverride,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="number" type="integer"/>
<aura:attribute name="recType" type="RecordType"/>
<aura:attribute name="myText" type="String"/>
<aura:attribute name="opp" type="Opportunity" default="{'sobjectType': 'Opportunity',
'Owner': '',
'Name': '',
'RecordType': '',
'Account__c': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
}"/><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/>
<table>
<tr>
<td width="45%">
<h1 style="font-weight:bold;font-size:12px;margin-left:5%">Opportunity Edit</h1>
</td>
<td width="55%">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</td>
</tr>
</table><br/>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Opportunity 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 width="45%">
<table>
<tr>
<td>
<p class="title">Owner</p>
<ui:outputText value="{!v.opp.Owner}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Opportunity Name</p>
<ui:inputText value="{!v.opp.Name}"/>
</td>
</tr>
<tr>
<td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Lead Source</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.LeadSource}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Web"/>
<ui:inputSelectOption text="Phone Enquiry"/>
<ui:inputSelectOption text="Partner Refferal"/>
<ui:inputSelectOption text="Purchased List"/>
<ui:inputSelectOption text="Other"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
<td width="10%"></td>
<td width="45%">
<table>
<tr>
<td>
<p class="title">Opportunity Record Type</p>
<ui:outputText value="{!v.opp.RecordType}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Amount</p>
<ui:inputNumber value="{!v.opp.Amount}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Stage</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.StageName}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Prospecting"/>
<ui:inputSelectOption text="Qualification"/>
<ui:inputSelectOption text="Needs Analysis"/>
<ui:inputSelectOption text="Value Proposition"/>
<ui:inputSelectOption text="Id. Decision Makers"/>
<ui:inputSelectOption text="Perception Analysis"/>
<ui:inputSelectOption text="Proposal/Price Quote"/>
<ui:inputSelectOption text="Negotiation/Review"/>
<ui:inputSelectOption text="Closed Won"/>
<ui:inputSelectOption text="Closed Lost"/>
</ui:inputSelect>
</td>
</tr>
</div>
<tr>
<td>
<label>Close Date</label>
<ui:inputDate displayDatePicker="true" value="{!v.opp.CloseDate}"/>
</td>
</tr>
</table>
</td>
</tr>
</thead>
</table>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Description Information">Description Information</span>
</h3>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr>
<td>
<p class="title">Description</p>
<ui:inputTextArea value="{!v.opp.Description}" rows="5" class="desc"/>
</td>
</tr>
</thead>
</table>
<br/>
<div class="de">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</div>
<br/>
</div>
</div>
</div>
</aura:component>
Controller:
({
create : function(component, event, helper) {
console.log('Create record');
//getting the opportunity information
var opp = component.get("v.opp");
opp.Account__c = null;
/***************Validation
if($A.util.isEmpty(opp.Account__c) || $A.util.isUndefined(opp.Account__c)){
alert('Account Name is Required');
return;
}*************************************************/
/*if(component.find("LeadSource").get("v.value") == ''){
alert('picklist field is required');
}*/
if(component.get("v.selectedLookUpRecord").Id != undefined){
opp.Account__c = component.get("v.selectedLookUpRecord").Id;
}
//Calling the Apex Function
var action = component.get("c.createRecord");
//Setting the Apex Parameter
action.setParams({
opp : opp
});
//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': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
};
//resetting the Values in the form
component.set("v.opp",newOpportunity);
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
//alert('Record is Created Successfully');
} else if(state == "ERROR"){
alert('Please enter Name,Account,Stage and Close Date');
}
});
//adds the server-side action to the queue
$A.enqueueAction(action);
},
cancel : function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
},
onSingleSelectChange: function(cmp,event,helper) {
var selectCmpValue = event.getSource().get("v.value");
//alert(selectCmpValue);
},
/*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"));
}
})
Am designed a lightning component show it for two recordtypes how can i show it?
Apex Class:
public with sharing class CreateOpportunityRecord
{
/**
* Create a new Opportunity Record
*
* @param Opportunity record to be inserted
*
*/
@AuraEnabled
public static String createRecord(Opportunity opp)
{
try
{
System.debug('CreateOpportunityRecord::createRecord::opp'+opp);
if(opp!= null)
insert opp;
}
catch (Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
return null;
}
return null;
}
}
Component:
<aura:component controller="CreateOpportunityRecord"
implements="lightning:actionOverride,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="number" type="integer"/>
<aura:attribute name="recType" type="RecordType"/>
<aura:attribute name="myText" type="String"/>
<aura:attribute name="opp" type="Opportunity" default="{'sobjectType': 'Opportunity',
'Owner': '',
'Name': '',
'RecordType': '',
'Account__c': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
}"/><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/>
<table>
<tr>
<td width="45%">
<h1 style="font-weight:bold;font-size:12px;margin-left:5%">Opportunity Edit</h1>
</td>
<td width="55%">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</td>
</tr>
</table><br/>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Opportunity 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 width="45%">
<table>
<tr>
<td>
<p class="title">Owner</p>
<ui:outputText value="{!v.opp.Owner}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Opportunity Name</p>
<ui:inputText value="{!v.opp.Name}"/>
</td>
</tr>
<tr>
<td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Lead Source</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.LeadSource}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Web"/>
<ui:inputSelectOption text="Phone Enquiry"/>
<ui:inputSelectOption text="Partner Refferal"/>
<ui:inputSelectOption text="Purchased List"/>
<ui:inputSelectOption text="Other"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
<td width="10%"></td>
<td width="45%">
<table>
<tr>
<td>
<p class="title">Opportunity Record Type</p>
<ui:outputText value="{!v.opp.RecordType}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Amount</p>
<ui:inputNumber value="{!v.opp.Amount}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Stage</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.StageName}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Prospecting"/>
<ui:inputSelectOption text="Qualification"/>
<ui:inputSelectOption text="Needs Analysis"/>
<ui:inputSelectOption text="Value Proposition"/>
<ui:inputSelectOption text="Id. Decision Makers"/>
<ui:inputSelectOption text="Perception Analysis"/>
<ui:inputSelectOption text="Proposal/Price Quote"/>
<ui:inputSelectOption text="Negotiation/Review"/>
<ui:inputSelectOption text="Closed Won"/>
<ui:inputSelectOption text="Closed Lost"/>
</ui:inputSelect>
</td>
</tr>
</div>
<tr>
<td>
<label>Close Date</label>
<ui:inputDate displayDatePicker="true" value="{!v.opp.CloseDate}"/>
</td>
</tr>
</table>
</td>
</tr>
</thead>
</table>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Description Information">Description Information</span>
</h3>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr>
<td>
<p class="title">Description</p>
<ui:inputTextArea value="{!v.opp.Description}" rows="5" class="desc"/>
</td>
</tr>
</thead>
</table>
<br/>
<div class="de">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</div>
<br/>
</div>
</div>
</div>
</aura:component>
Controller:
({
create : function(component, event, helper) {
console.log('Create record');
//getting the opportunity information
var opp = component.get("v.opp");
opp.Account__c = null;
/***************Validation
if($A.util.isEmpty(opp.Account__c) || $A.util.isUndefined(opp.Account__c)){
alert('Account Name is Required');
return;
}*************************************************/
/*if(component.find("LeadSource").get("v.value") == ''){
alert('picklist field is required');
}*/
if(component.get("v.selectedLookUpRecord").Id != undefined){
opp.Account__c = component.get("v.selectedLookUpRecord").Id;
}
//Calling the Apex Function
var action = component.get("c.createRecord");
//Setting the Apex Parameter
action.setParams({
opp : opp
});
//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': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
};
//resetting the Values in the form
component.set("v.opp",newOpportunity);
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
//alert('Record is Created Successfully');
} else if(state == "ERROR"){
alert('Please enter Name,Account,Stage and Close Date');
}
});
//adds the server-side action to the queue
$A.enqueueAction(action);
},
cancel : function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
},
onSingleSelectChange: function(cmp,event,helper) {
var selectCmpValue = event.getSource().get("v.value");
//alert(selectCmpValue);
},
/*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"));
}
})
Instead of using standard record type selection you need to use custom record type selection component.
For that create a Lightning component to select record type. Inside it use aura:if conditions and call your components.
For ex.
1. If you select Record Type A call Lightning component 1,
2. If you select Record Type B call Lightning component 2.
After creation of Lightning Components go to object and select the action/button "New" and check Skip Record Type Selection.
In Lightnning override select the Custom Record Type Lightning Component.
Hope this help.
Please mark Solved if it works.
Mahalo,
Aamir AH Khan
Lead Salesforce Lightning Developer