• Ronaldo Costa 8
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hello, I have the following simple code:
 
public class SaveAndNewC {
    
    @AuraEnabled
    public static Id saveDetails(Lead regForm1){
        // DML operation to save Lead Details   
        INSERT regForm1;
        return regForm1.Id; 
    }
}

But my current class is only covering 66%:
 
@isTest
private class SaveAndNewC_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    Lead lead_Obj = new Lead(LastName = 'LastName836', FirstName = 'First211', Company = 'Company565', Phone = '54343-13889', Status = 'Unqualified', IsConverted = false, IsUnreadByOwner = false);
    Insert lead_Obj;
    test.stopTest();
  }
  static testMethod void test_saveDetails_UseCase1(){
    List<Lead> lead_Obj  =  [SELECT LastName,FirstName,Company,Phone,Status,IsConverted,IsUnreadByOwner from Lead];
    System.assertEquals(true,lead_Obj.size()>0);
    SaveAndNewC obj01 = new SaveAndNewC();
    SaveAndNewC.saveDetails(lead_Obj[0]); 
      //lead_Obj[0]
  }
}

Can you please help? Upon deployment is says as follows:

SaveAndNew

C_Testtest_saveDetails_UseCase1System.DmlException: Insert failed. First exception on row 0 with id 00Qf400000IsyiqEAB; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] 

Stack Trace: Class.SaveAndNewC.saveDetails: line 6, column 1 Class.SaveAndNewC_Test.test_saveDetails_UseCase1: line 14, column 1
Hi,
When I click "submit", Action failed: c:Lead$controller$doInit [helper.getAllRecords is not a function]User-added image
My Code For Lead
<aura:component controller="LeadRecord"
            access="global"    implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
    
    
    <!-- Include Static Resource-->
    <ltng:require styles="/resource/bootstrap/css/bootstrap.min.css"
                  scripts="/resource/bootstrap/js/jquery.js,/resource/bootstrap/js/bootstrap.min.js"/>
    
    <!-- Define Attribute-->
    <aura:attribute name="LeadRec" type="Lead" default="{'sobjectType': 'Lead',
                                                     'FirstName': '',
                                                     'LastName': '',
                                                     'Email': '',
                                                     'Title': '',                            
                                                     'phone': ''
                                                     }"/>
    
    <!-- Display a header with details about the account -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.Lead.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
                   slds-truncate slds-align-left">Create New Lead Data</h1>
    </div>
    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required" title="required">* </abbr>Frist Name</label>
        <div class="slds-form-element__control">
            <input  aura:id="FirstName"    type="text" id="form-element-03"  value="{!v.LeadRec.FirstName}"  required="" class="slds-input" />
        </div>
    </div>
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required" title="required">* </abbr>Last Name</label>
        <div class="slds-form-element__control">
            <input  aura:id="LastName"         type="text" id="form-element-03"  value="{!v.LeadRec.LastName}" required="" class="slds-input" />
        </div>
    </div>
    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required"   title="required">* </abbr>Company</label>
        <div class="slds-form-element__control">
            <input aura:id="company"  type="text" id="form-element-03"  value="{!v.LeadRec.Company}"  required="" class="slds-input" />
        </div>
    </div>
    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required" > </abbr>Title</label>
        <div class="slds-form-element__control">
            <input aura:id="Title"  type="text" id="form-element-03"  value="{!v.LeadRec.Title}"  required="" class="slds-input" />
        </div>
    </div>
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" />

    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required" > </abbr>Email </label>
        <div class="slds-form-element__control">
            <input aura:id="Email"  type="text" id="form-element-03"  value="{!v.LeadRec.Email}"  required="" class="slds-input" />
        </div>
    </div>   
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="form-element-03">
            <abbr class="slds-required" > </abbr>phone </label>
        <div class="slds-form-element__control">
            <input aura:id="phone" type="text" id="form-element-03"  value="{!v.LeadRec.phone}"  required="" class="slds-input" />
        </div>
    </div>   
    
    <div class="col-md-4 text-center" >
        
        <lightning:button variant="brand" label="Submit" onclick="{!c.createLeadInfo}"/>
    </div>
</aura:component>

LeadRecordApex:
public with sharing class LeadRecord {
@AuraEnabled
    public static list<Lead> getRecords(){
        return [select id, FirstName,LastName,Company,phone,Email,Title from Lead];
    }  
    
    
    
    
    @AuraEnabled
    public static Lead createRecord (Lead  LeadRec){
      upsert LeadRec;
        return LeadRec;
}
}

LeadControllerCode:
({
    doInit:function(component,event,helper){
        helper.getAllRecords(component);
    },
    
    
    
    createLeadInfo : function(component, event, helper) {
        console.log('Create record');
        var saveLeadAction=component.get("c.LeadRec");
       
        
        //Validation
        if($A.util.isEmpty(LeadRec.FirstName) || $A.util.isUndefined(LeadRec.FirstName)){
            // alert('First Name is Required');
            return;
        }            
        if($A.util.isEmpty(LeadRec.LastName) || $A.util.isUndefined(LeadRec.LastName)){
            // alert('Last Name is Required');
            return;
        }
        if($A.util.isEmpty(LeadRec.Email) || $A.util.isUndefined(LeadRec.Email)){
            // alert('Email is Required');
            return;
        }
        if($A.util.isEmpty(LeadRec.Title) || $A.util.isUndefined(LeadRec.Title)){
            // alert('Email is Required');
            return;
        }
        
        
        
        if($A.util.isEmpty(LeadRec.Company) || $A.util.isUndefined(LeadRec.Company)){
            
            return;
        }
        //Calling the Apex Function
        var saveLeadAction = component.set("c.LeadRec");
        
        //Setting the Apex Parameter
        saveLeadAction.setParams({
            "Lead":component.get("v.LeadRec")
        });
        
        //Setting the Callback
        saveLeadAction.setCallback(this,function(a){
            //get the response state
            var state = a.getState();
            
            //check if result is successfull
            if(state == "SUCCESS"){
                //Reset Form
                var newCandidate = {'sobjectType': 'Lead',
                                    'FirstName': '',
                                    'LastName': '',
                                    'Company': '',
                                    'Title': '',
                                    'Phone': '',
                                    'Email': ''
                                   };
                //resetting the Values in the form
                component.set("v.LeadRec",newCandidate);
                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(saveLeadAction);
        
    }
})

LeadApp Code:
<aura:application extends="force:slds" >
  <lightning:layout>
        <lightning:layoutItem padding="around-large">
            <h1 class="slds-text-heading_large">Lead Information</h1>
        </lightning:layoutItem>
    </lightning:layout>
    
    <aura:dependency resource="c:Lead" />
    <c:Lead />
</aura:application>
 

 
<aura:component controller="ContactControllerlightning">
	<aura:attribute name="contactObj" type="Contact" default="{'sobjectType':'Contact',
                                                              'FirstName':'' ,
                                                              'LastName':'' ,
                                                              'phone':''}"/>
    <aura:attribute name="contactId" type="String"/>
 
    <lightning:input value="{!v.contactObj.FirstName}" label="First Name" placeholder="Enter FirstName"/>
    <lightning:input vlaue="{!v.contactObj.LastName}" label="Last Name" placeholder="Enter LastName"/>
    <lightning:input value="{!v.contactObj.phone}" label="Phone" placeholder="Enter Phone"/>
        <lightning:button variant="brand" label="Save" title="Save" onclick="{!c.dosave}"/>

  

    
    
    
</aura:component>
 
({
	dosave : function(component, event, helper) {
        var action = component.get("c.createContact");
        
        action.setParams({'contObj':component.get('v.contactObj')});
        
        action.setCallback(this,function(data){
         component.set('v.contactId',data.getReturnValue())
        });
		$A.enqueueAction(action);
	}
})

 
Hi All,

I have created visual flow to create order from Quote with line items assignment. Have a generate button on quote which would tigger the flow and order gets created. 
Issue is the order gets created and but it stays on the quote page itself. My requirement is once the order is created it should navigate to Order screen with created order.

Can someone help!