• Sainath Ram
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I done with this code 
Contactcontroller class:
public class contactcontroller {
    @AuraEnabled
  public static Employee_Details__c save(Employee_Details__c emp)
    {
        List<Employee_Details__c> emplist = [select id,name,DOB__c,Phone_Number__c, Employee_ID__c from Employee_Details__c];
        for(Employee_Details__c emp1:emplist){
            if(emp.Employee_ID__c==emp1.Employee_ID__c){
                emp1.Name=emp.Name;
                emp1.DOB__c=emp.DOB__c;
                emp1.Phone_Number__c=emp.Phone_Number__c;
                emplist.add(emp);
                
            }
            
        }
        upsert emp;
        return emp;
    }

}

controller:
({
saveemp: function(component, event, helper) {
    var newemp = component.get("v.newemployee");
    var action = component.get("c.save");
     action.setParams({ 
        "emp": newemp
    });
     action.setCallback(this, function(a) {
           var state = a.getState();
            if (state === "SUCCESS") {
                var Employee_ID__c = a.getReturnValue();
               alert("success");
            }
         else
         {
              alert("Fail");
         }
        });
    $A.enqueueAction(action)
}})

component:
<aura:component  controller="contactcontroller" >
    
<aura:attribute name="newemployee" type="Employee_Details__c"  default="{ 'sobjectType': 'Employee_Details__c',
                     'Employee_ID__c': '','Name':'','Phone_Number__c':'','Phone_Number__c':'',}"/>
<form>
    <lightning:card title="Employee Details">
    <div class="slds-col slds-p-horizontal_medium">       
       <lightning:input aura:id="empField" type="Auto Number" value="{!v.newemployee.Employee_ID__c}" label ="Employee Id" style="width:20%;"/>
       <lightning:input aura:id="emptField" type="text"  label="Name"  value="{!v.newemployee.Name}" style="width:20%;"/>
       <lightning:input aura:id="empField" type="Phone"  value="{!v.newemployee.Phone_Number__c}"  label="Phone Number" style="width:20%;"/>
       <lightning:input aura:id="empField" type="date"  value="{!v.newemployee.DOB__c}"  label="DOB" style="width:20%;"/><br/>
       <lightning:button aura:id="empField" label="Save" onclick="{!c.saveemp}"/>
    </div>
    </lightning:card>
</form>
   
</aura:component>


please can any one help me
Thanks 
if record is already exists update record other wise insert record by using lightning component 
I done with this code 
Contactcontroller class:
public class contactcontroller {
    @AuraEnabled
  public static Employee_Details__c save(Employee_Details__c emp)
    {
        List<Employee_Details__c> emplist = [select id,name,DOB__c,Phone_Number__c, Employee_ID__c from Employee_Details__c];
        for(Employee_Details__c emp1:emplist){
            if(emp.Employee_ID__c==emp1.Employee_ID__c){
                emp1.Name=emp.Name;
                emp1.DOB__c=emp.DOB__c;
                emp1.Phone_Number__c=emp.Phone_Number__c;
                emplist.add(emp);
                
            }
            
        }
        upsert emp;
        return emp;
    }

}

controller:
({
saveemp: function(component, event, helper) {
    var newemp = component.get("v.newemployee");
    var action = component.get("c.save");
     action.setParams({ 
        "emp": newemp
    });
     action.setCallback(this, function(a) {
           var state = a.getState();
            if (state === "SUCCESS") {
                var Employee_ID__c = a.getReturnValue();
               alert("success");
            }
         else
         {
              alert("Fail");
         }
        });
    $A.enqueueAction(action)
}})

component:
<aura:component  controller="contactcontroller" >
    
<aura:attribute name="newemployee" type="Employee_Details__c"  default="{ 'sobjectType': 'Employee_Details__c',
                     'Employee_ID__c': '','Name':'','Phone_Number__c':'','Phone_Number__c':'',}"/>
<form>
    <lightning:card title="Employee Details">
    <div class="slds-col slds-p-horizontal_medium">       
       <lightning:input aura:id="empField" type="Auto Number" value="{!v.newemployee.Employee_ID__c}" label ="Employee Id" style="width:20%;"/>
       <lightning:input aura:id="emptField" type="text"  label="Name"  value="{!v.newemployee.Name}" style="width:20%;"/>
       <lightning:input aura:id="empField" type="Phone"  value="{!v.newemployee.Phone_Number__c}"  label="Phone Number" style="width:20%;"/>
       <lightning:input aura:id="empField" type="date"  value="{!v.newemployee.DOB__c}"  label="DOB" style="width:20%;"/><br/>
       <lightning:button aura:id="empField" label="Save" onclick="{!c.saveemp}"/>
    </div>
    </lightning:card>
</form>
   
</aura:component>


please can any one help me
Thanks 
if record is already exists update record other wise insert record by using lightning component