Skip to main content

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 }     }                                           }

1 resposta
  1. 18 de mai. de 2022, 12:10

    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

    }

    }

    }

0/9000