0

I have a lightning component to create contact record and list of child records. On click of add button, contact is getting created and when it is calling the next method to create child record i get the system error saying:

FATAL_ERROR System.UnexpectedException: Salesforce System Error: 204449845-24512 (-1753594556) (-1753594556)

Here is my code.

Lightning Component:

<aura:component access="global" controller="CreateRecord">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
<aura:attribute name="child" type="ChildWrapper[]"/>
<aura:attribute name="contact" type="contact" default="{'sobjectType': 'contact',
                         'FirstName': '',
                         'LastName': '',
                         'Email' : '',
                       }"/>

    <c:collapse title="Candidate Information">
       <div class="container-fluid">
        <h3>Personal Information</h3>
        <fieldset class="slds-form--compound">
            <div class="slds-form-element__group">
                <div class="slds-form-element__row">
                    <div class="slds-form-element slds-size--1-of-2">
                        <label class="slds-form-element__label" for="input-01">First Name</label>
                        <ui:inputText class="slds-input" value="{!v.contact.FirstName}"/>
                    </div>
                    <div class="slds-form-element slds-size--1-of-2">
                        <label class="slds-form-element__label" for="input-02">Surname</label>
                        <ui:inputText class="slds-input" value="{!v.contact.LastName}"/>
                    </div>  
                </div>
                <div class="slds-form-element__row">
                    <div class="slds-form-element slds-size--1-of-2">
                        <label class="slds-form-element__label" for="input-02">Email</label>
                        <ui:inputText class="slds-input" value="{!v.contact.Email}"/>
                    </div>  
            </div>
        </fieldset>
       </div>
    </c:collapse>
    <c:collapse title="History">
       <div class="slds">
           <ui:button class="btn btn-default" press="{!c.addrow}">Add</ui:button>
        <table class="slds-table slds-table--bordered slds-table--striped">
            <thead>
            <tr>
                <th/>
                <th scope="col"><span class="slds-truncate">Company Name</span></th>
                <th scope="col"><span class="slds-truncate">Activities</span></th>
                <th scope="col"><span class="slds-truncate">Function</span></th>
                <th scope="col"><span class="slds-truncate">Place</span></th>
                <th scope="col"><span class="slds-truncate">Delete</span></th>
            </tr>
            </thead>
            <tbody>
         <aura:iteration items="{!v.child}" var="wrap">
            <tr>
                <td><input type="hidden" name="index" value="{!wrap.Index}"/></td>
                <td><ui:inputText class="slds-input" value="{!wrap.childRecord.Name}"/></td>
                <td><ui:inputText class="slds-input" value="{!wrap.childRecord.Activities__c}"/></td>
                <td><ui:inputText class="slds-input" value="{!wrap.childRecord.Function__c}"/></td>
                <td><ui:inputText class="slds-input" value="{!wrap.childRecord.Place__c}"/></td>
                <td><a href="#" data-record="{!wrap.Index}" class="slds-truncate" onclick="{!c.deleterow}" >Delete  
                    </a>
                </td>
              </tr>
        </aura:iteration>
            </tbody>
        </table>
        </div> 
    </c:collapse>
 <div class="col-md-4 text-center">
                <ui:button class="btn btn-default" press="{!c.create}">Create</ui:button>
            </div>  

Javascript Controller:

({
    create : function(component, event, helper) {
        console.log('Create record');
        var contact = component.get("v.contact");
        console.log(JSON.stringify(contact)+'contact');
        var history = component.get("v.child");
        console.log(JSON.stringify(history)+'history');

        var action = component.get("c.createRecord");
        action.setParams({
            "contact" : contact,
            "childrecs" : history
        });

        action.setCallback(this,function(a){
            var state = a.getState();
            if(state == "SUCCESS"){
                var contact = {'sobjectType': 'contact',
                                    'FirstName': '',
                                    'LastName': '',
                                    'Email' : '',
                                   };
                component.set("v.contact",contact);
                alert('Record is Created Successfully');
            } else if(state == "ERROR"){
                alert('Error in calling server side action');
            }
        });

        $A.enqueueAction(action);
}

Apex Controller:

public class CreateRecord {
 @AuraEnabled
    public static void CreateRecord (Contact contact,List<ChildWrapper> childrecs){
        system.debug('inside apex create method');
        try{
            if(contact != null){
                insert contact;
                system.debug('contact created');
                string contactId = contact.id;
                system.debug(contactId);
                createChildRecords(childrecs,contactId);
            } 
        } catch (Exception ex){
            system.debug('Error inserting contact');
        }  
    } 

@AuraEnabled
    public static void createChildRecords(List<ChildWrapper> childRecords,String conId){
        List<Child__c> newChild = new List<Child__c>();
        for(ChildWrapper w : childRecords){ //Fatal Error is happening at this line
            newChild.add(w.childRecord);
            for(Child__c s : newChild){
                s.Contact__c = conId;
            }
        }
        try{
            if(newChild != null){
                insert newChild;
            } 
        } catch (Exception ex){
            system.debug('Error inserting newChild'+ex);
        }  
    } 
}

Wrapper Class:

public class ChildWrapper {
    @AuraEnabled public Integer Index;
    @AuraEnabled public Child__c childRecord;
    public childWrapper(Integer index,Child__c childrec){
        Index = index;
        childRecord = childrec;
    }
}
  • Did you enable the debug logs to see at which point in the code it throws the error? – svenf Feb 14 '17 at 14:29
  • yes. I enabled the debug logs. It is showing the error on this line createChildRecords(childrecs,contactId); – ləːnə Feb 14 '17 at 15:16
  • which errors message is shown in apex debug logs? – Patlatus Feb 14 '17 at 16:10
  • 21:37:25:084 METHOD_EXIT [12]|01p0E000000Cqwt|CreateRecord.createChildRecords(List<ChildWrapper>, String) 21:37:25:085 FATAL_ERROR System.UnexpectedException: Salesforce System Error: 404780030-7476 (-1753594556) (-1753594556) – ləːnə Feb 14 '17 at 16:18
  • It is going inside this method "createChildRecords" and it gets aborted on the for loop "for(ChildWrapper w : childRecords){" – ləːnə Feb 14 '17 at 16:20
0

Before passing the list of Wrapper Class records to your Apex controller - use JSON.Stringify and pass them as a String.

var records = JSON.stringify(theRecords); 

Your Apex controller must be expecting a String as an argument instead of List<YourWrapperClass>.

Inside your Apex deserialize your String:

List<YourWrapperClass> sRecords = (List<YourWrapperClass>)System.JSON.deserialize(records, List<YourWrapperClass>.class);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.