You need to sign in to do that
Don't have an account?
Deepika G P
trigger not getting parent field values in email body
Hi have an parent object project and child object project schedule . When the assigned to is changed to other user email needs to be sent for that i have written trigger below is the bit of that code. Now i want to pull the field values from project ,the trigger is written on project schedule.
When i try to pull the values i am getting null eg:Project:'+ PSOne.Project__r.Name ='null '
Can anyone help me on this please?
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
User current_user=[SELECT Email FROM User WHERE Id= :UserInfo.getUserId()] ;
String emailfromAddr = current_user.Email;
String emailtoAddr = PSOne.Assigned_To_User__c;
list<string> listmail= new list<string>();
listmail.add(emailfromaddr);
listmail.add(emailtoaddr);
mail.setToAddresses(listmail);
mail.setSubject(PSOne.Phase__c+' record is assigned to you ' + PsOne.Name);
mail.setPlainTextBody('To:'+ emailtoAddr + '\n has made an change the following Task:'+
'\n Subject:'+ PsOne.Phase__c+ '\n Project:'+ PSOne.Project__r.Name +'\n Due Date:'+PSOne.Project__r.Due_Date__c+'\n Priority:'+ PSOne.Project__r.Priority__c+
'\n For more details click the link below:{0}' );
system.debug('33333333'+ PsOne.Project__r);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
When i try to pull the values i am getting null eg:Project:'+ PSOne.Project__r.Name ='null '
Can anyone help me on this please?
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
User current_user=[SELECT Email FROM User WHERE Id= :UserInfo.getUserId()] ;
String emailfromAddr = current_user.Email;
String emailtoAddr = PSOne.Assigned_To_User__c;
list<string> listmail= new list<string>();
listmail.add(emailfromaddr);
listmail.add(emailtoaddr);
mail.setToAddresses(listmail);
mail.setSubject(PSOne.Phase__c+' record is assigned to you ' + PsOne.Name);
mail.setPlainTextBody('To:'+ emailtoAddr + '\n has made an change the following Task:'+
'\n Subject:'+ PsOne.Phase__c+ '\n Project:'+ PSOne.Project__r.Name +'\n Due Date:'+PSOne.Project__r.Due_Date__c+'\n Priority:'+ PSOne.Project__r.Priority__c+
'\n For more details click the link below:{0}' );
system.debug('33333333'+ PsOne.Project__r);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
Hi Deepika,
We will not the refrence object fields value in Trigger context variable for that we need to query on Project object and get all the require fields as we will get the only Project Id from Trigger.new or Trigger.newMap.
Please let me know if this help and require any help to get the Project and how how to use etc..
Thanks
All Answers
Hi Deepika,
We will not the refrence object fields value in Trigger context variable for that we need to query on Project object and get all the require fields as we will get the only Project Id from Trigger.new or Trigger.newMap.
Please let me know if this help and require any help to get the Project and how how to use etc..
Thanks
project__c p=[select id,name,Due_Date__c,Priority__c from project__c where id=:PSOne.Project__c limit 1];
mail.setPlainTextBody('To:'+ emailtoAddr + '\n has made an change the following Task:'+
'\n Subject:'+ PsOne.Phase__c+ '\n Project: '+ p.Name +'\n Due Date: '+ p.Due_Date__c +'\n Priority:'+ p.Priority__c+
'\n For more details click the link below:+"' + fullTaskURL+'" ');
result:
Subject:Internal Kickoff Meeting
Project:initial testing
Due Date:null
Priority:null