function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Long Nguyen 19Long Nguyen 19 

Account Name is Null

Hi Expert,

In my trigger below, new Account is created when trigger happens on Appointment__c object:
if(Trigger.isInsert){
            for(Appointment__c newRec : Trigger.new) {
                    Account converted = new Account(
                    LastName =  UserInfo.getLastName(),
                    FirstName = UserInfo.getFirstName(),
                    ABN_ACN__c = newRec.ABN__c,
                    Entity_Name__c = newRec.Legal_Entity_Name__c,
                    Trading_Name__c = newRec.Business_Trading_Name__c,
                    Owners__c = newRec.Owner_s__c,
           
                    );
                System.debug('long converted.Name' + converted.Name);
                newRec.Legal_Entity_Name__c = converted.Name;
                lstAccounts.add(converted);
            }
            upsert lstAccounts;
    }
This problem is that converted.Name is Null. As i know, when First Name and Last name are populated for an Account then Account.Name should be populated also. Pls show me the way to fix this issue?

 
Best Answer chosen by Long Nguyen 19
Sanjay.GeorgeSanjay.George
HiLong,

Assuming you are using person Accounts,

The Name field is populated only after the DML runs on the Account. you can't get it in the debug log.

All Answers

Sampath KumarSampath Kumar
Hi Long,

For an Account Field, name is the text field which is not derived, we need to assign the value, where as for user name is derived from first name and last name, not for an account.

Regards
Sampath Kumar Goud
Sanjay.GeorgeSanjay.George
HiLong,

Assuming you are using person Accounts,

The Name field is populated only after the DML runs on the Account. you can't get it in the debug log.
This was selected as the best answer
Mudasir WaniMudasir Wani
Hi Long,

To get the name of the account you need to fetch the record 
Use SOQL in after Insert context.
Let me know if you have any question.

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help