public class AccountHandller { @AuraEnabled public static Account createAccount(String accountName) { try { Account acct = new Account(Name='accountName'); // Insert the account insert acct; return acct; // Get this ID. // Add a contact to this account. Contact con = new Contact( FirstName='Joe', LastName='Smith', Phone='415.555.1212', AccountId=acct.Id); insert con; } catch (DmlException e) { System.debug('A DML exception has occurred: ' + e.getMessage()); return null; //catch the failed DML and then return null } } }
Hello @Jyoti Bhosale
Please try below code:
public class AccountHandller {
@AuraEnabled
public static Account createAccount(String accountName) {
try {
Account acct = new Account(Name='accountName');
// Insert the account
insert acct;
// Get this ID.
// Add a contact to this account.
Contact con = new Contact(FirstName='Joe',LastName='Smith',Phone='415.555.1212',AccountId=acct.Id);
insert con;
return acct;
}
catch (DmlException e) {
System.debug('A DML exception has occurred: ' + e.getMessage());
return null; //catch the failed DML and then return null
}
}
}