Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: Trigger to send email alert on creation of chi...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Trigger to send email alert on creation of child object to the parent object user field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 05:49 AM
Hi,
I have written one trigger which sent email notification to the user who's in parent object...
this is my code:
Trigger mailSend on Quality_of_Delivery__c(after insert){
List<Project__c> lstPrj = new List<Project__c>();//parent obj
set<Id> setId=new set<Id>();
lstprj=[select id,Dev_Specialist__c from Project__c];
for(Project__c proj : lstprj){
setId.add(proj.Dev_Lead_User__c);//I'm sending the email to the Dev_Lead_User__c and this guy is in parent object"Project__c"
}
//List<User> lstuser=[select Id,email from User where ID In:setId];
for(Quality_of_Delivery__c Qod : Trigger.new)
{
EmailTemplate et=[Select id from EmailTemplate where name=:'Update QOD Fields'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
string[] toAddress = new string[]{};
mail.setTargetObjectId(Qod.Project__r.Dev_Lead_Use
toAddress.add(Qod.Project__r.Dev_Lead_User__r.emai
system.debug('toAddress :'+toAddress);
mail.setSaveAsActivity(false);
mail.setToAddresses(toAddress);
//System.debug( mail.setTargetObjectId);
mail.setTemplateId(et.id);
mail.setToAddresses(toAddress);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
}
}
need help on this since this is not working
Re: Trigger to send email alert on creation of child object to the parent object user field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 06:52 AM
Hi Irish,
Please be specific as what is not working here.
If this answers your query,please mark this as solution so that it would be useful for others.
Re: Trigger to send email alert on creation of child object to the parent object user field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 08:11 AM
I'm not able to send the email to the Dev_Lead_user__c
Re: Trigger to send email alert on creation of child object to the parent object user field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2013 08:47 AM
Irish,
the way you are populating toAddress that does not look good to me.You need to query the field using SOQL and then populate the toAddress to it.
If this answers your query,please mark this as solution so that it would be useful for others.

