Skip to main content
deleted 27 characters in body; edited tags
Source Link
glls
  • 20.3k
  • 19
  • 49
  • 83

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,any one please help me out.:

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');
        }
    }
}

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,any one please help me out.

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');
        }
    }
}

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');
        }
    }
}

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,any one please help me out.

trigger CheckAcctPhoneBlank on Contact (Before insert) {

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');
    
     }
    
 }
}

}

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,any one please help me out.

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');
    
     }
    
 
}

}

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,any one please help me out.

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');
        }
    }
}
Source Link
kishore
  • 21
  • 1
  • 3

Check parent field is null before inserting child record

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,any one please help me out.

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');
    
    }
    

}

}