You need to sign in to do that
Don't have an account?
Trevor Viall
How do I check an object within an object?
This is probably a fairly simple question but, I am still fairly new. How do I check an object within an object? I am making a trigger on the Account object and one of the requirements is to check the contacts email and phone and compair it with the accounts email and phone. How exactly do I check this information while setting the trigger to account?
snippit of the code:
public with sharing class AccountTriggerHandler {
public static void afterupdate(Map<Id, Account> oldRecs, list <Account> newrecs){
//Checks for changes in account
Integer task =0;
for (account a: newrecs){
if (a.Email__c == (a.Contact__c).Email__c)
{a.EmailCheck__c = true;
task++;}
if (a.Phone == (a.Contact__c).Phone)
{a.PhoneCheck__c = true;
task++;}
snippit of the code:
public with sharing class AccountTriggerHandler {
public static void afterupdate(Map<Id, Account> oldRecs, list <Account> newrecs){
//Checks for changes in account
Integer task =0;
for (account a: newrecs){
if (a.Email__c == (a.Contact__c).Email__c)
{a.EmailCheck__c = true;
task++;}
if (a.Phone == (a.Contact__c).Phone)
{a.PhoneCheck__c = true;
task++;}
Best Answer chosen by Trevor Viall
David Zhu 🔥
Account is one to many relationship to Contact Object. You may use the following code as reference.