0

I am trying to send an email when trigger gets fired. I have 2 custom objects

  1. Quote(child)

  2. supplier(Parent)

    When trigger fires user gets mail with corrosponding fields. But in those field there is a parent object field which I'm getting NULL in email.

Below is my code for your reference.

 trigger SendEmailCountrywise on Quote__c (after update) {

Quote__c Quote = [select id, PR_Number__c, RFQ_Status__c,RFQ_Supplier__r.name, RFQ_Supplier__c from Quote__c limit 1];
String loggedinuser=userInfo.getUserId();
User logged=[select id,name,Country__c from user where id=:loggedinuser];

List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();

if(Quote.RFQ_Status__c=='Submitted To Supplier'){
if(logged.Country__c =='IN'){
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    //system.debug('******Supplier Name'+RFQ_Supplier__r.name );
    mail.setToAddresses(new String[]{'[email protected]'});
    String body ='<html><body> Dear,<br><br> ' +logged.name+ ' submitted PR-'+Quote.PR_Number__c+ ' to '+Quote.RFQ_Supplier__r.name + '  with SLA clock <br><br> Thanks, <br><br> ZIS Support</body></html>';
    mail.setHtmlBody(body);
    mail.setSubject(logged.name+'_PR-'+Quote.PR_Number__c);
    emails.add(mail); 
    

}
}
Messaging.sendEmail(emails);

}

Quote.RFQ_Supplier__r.name

this field is getting null value which is present in body.

10
  • Hi @sfdcPro did you check whether the Quote.RFQ_Supplier__r.name contain any value after completing soql statement.
    – Anu
    Aug 7, 2015 at 9:52
  • I checked, It is giving me NULL only
    – SfdcPro
    Aug 7, 2015 at 10:13
  • is this related with permission issue?
    – highfive
    Aug 7, 2015 at 10:15
  • No. There is no issue like permission.
    – SfdcPro
    Aug 7, 2015 at 10:16
  • 1
    @SfdcPro Hi, I would suggest you to put a debug statement on Quote record and get the quote id which your SOQL is returning. Check if RFQ_Supplier__c is blank in that record If yes then no value will be fetched. Thanks!
    – Ruchi
    Aug 7, 2015 at 10:28

1 Answer 1

1

You would change the Query to

Quote__c Quote = [select id, PR_Number__c, RFQ_Status__c,RFQ_Supplier__r.name, RFQ_Supplier__c from Quote__c 
WHERE RFQ_Supplier__c != null
AND RFQ_Supplier__r.name != null
limit 1];

So, it will close all the ways to get null value in code. Also, it doesn't look like that you are looking for specific record. You just want any Quote. So, using these filters would be fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .