Read a Contact's Account
A child-to-parent query uses dot notation.
Your task
Query three tagged Contacts, read each one's Account name through the relationship, and upper-case it without crashing on the Contact that has no Account.
String tag = 'AS-Q306-' + UserInfo.getUserId() + '-' +
String.valueOf(Datetime.now().getTime());
Account parent = new Account(Name = tag);
insert parent;
List<Contact> seeded = new List<Contact>{
new Contact(LastName = tag + '-LinkedA', AccountId = parent.Id),
new Contact(LastName = tag + '-LinkedB', AccountId = parent.Id),
new Contact(LastName = tag + '-Orphan')
};
insert seeded;
String contactPattern = tag + '-%';
Integer linkedCount = 0;
Integer orphanCount = 0;
Boolean parentNamesMatch = true;
String orphanParentName = 'unknown';
System.debug('Contacts with an Account: ' + linkedCount);
System.debug('Parent names match: ' + parentNamesMatch);
System.debug('Contacts without an Account: ' + orphanCount);
System.debug('Orphan parent name: ' + orphanParentName);Requirements
Contacts with an Account: 2should be built from the loopAccount.Nameshould be presenttoUpperCase(should be presentContacts with an Account: 2should be printedParent names match: trueshould be printedContacts without an Account: 1should be printedOrphan parent name: nullshould be printed