As per my requirement,I need to check whether phone field of account object is null before inserting contact.If it is null,I should not allow user to create contact.I created trigger for this scenario,but unable to achieve functionality .I am posting my trigger code:
trigger CheckAcctPhoneBlank on Contact (Before insert) {
for(Contact con:[Select id,account.phone,account.name from Contact where id in:trigger.new]){
system.debug('Contact size**'+con);
system.debug('??test2??');
system.debug('Phone details**'+con.account.phone);
if(con.account.phone == null){
con.addError('Contact cannot be inserted');
}
}
}