You need to sign in to do that
Don't have an account?
Error insert record of case from component Lightning
Good Morning folks,
I have a component to inset case, but is experiencing an error of log:
"first error: INVALID_FIELD, Cannot specify both an external ID reference Account and a salesforce id, AccountId: []"
Basically this code :
Component.cmp
<aura:attribute name="caseObj" type="case" default="{'sobjectType': 'Case',
'AccountId': '',
'MSISDN__c': '',
'Status': ''
}"/>
<label>Montadora</label>
<force:inputField aura:id="AccountId" value="{!v.caseObj.AccountId}"/>
</div>
<div class="form-group">
<label>MSISDN</label>
<ui:inputText class="form-control" value="{!v.caseObj.MSISDN__c}"/>
</div>
<div class="form-group">
<label>Status</label>
<force:inputField aura:id="Status" value="{!v.caseObj.Status}"/>
</div>
-----------------------------------------------------------
controller.js
create: function(component, event, helper) {
console.log('Create record');
var caseObj = component.get("v.caseObj");
var action = component.get("c.createRecord");
action.setParams({
caseObj : caseObj
});
-------------------------------------------------------------------
Class.apxc
@AuraEnabled
public static void createRecord (Case caseObj){
try{
System.debug('NovoCasoComponentController::createRecord::caseObj'+ caseObj);
if(caseObj != null){
insert caseObj;
}
} catch (Exception ex){
}
}
Thanks
Greetings to you!
Just add below line before inserting the Case in the Apex method.
You can see in debug logs, it is already having AccountId in it, I nullified Account from the caseObj.
So, change your Apex method to:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Just add below line before inserting the Case in the Apex method.
You can see in debug logs, it is already having AccountId in it, I nullified Account from the caseObj.
So, change your Apex method to:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Perfect!!
many many thank you!
Have an excellent day.