Find your content:

Search form

You are here

Generate an email alert to the Issue Owner

 
Share

I have created a custom object(1) in my organization with a check box and a look up field link to the main object(1).

I need to create a task when a user, other than the Owner of object(1), creates/inserts a new record. The task needs to generate an email alert to the Issue Owner of the main object(1).

Only display records if check-box is ticked. there is a description field in object(1) that should be the subject of email

Note: object(2) is the related list of object(1).


Attribution to: rakesh

Possible Suggestion/Solution #1

Assuming we have a lookup relationship we can think of after insert and after update trigger that checks that owner of parent and child is different and also we can check if the flag field is true send the Outbound Email message .You may like to bulkify the trigger while sending outbound email messages due to governor limits .


Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

You could do this two ways, one all in a trigger

Trigger Object2After(After insert){

List<Id> parentIds = new List<Id>{};

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

For(Object2__c obj : trigger.new)
ParentIds.add(obj.Object1__c);

Map<Id, Object1__c> idObj1Map = new Map<Id, Object1__c>([select Id, Name, OwnerId from Object1__c where Id IN :parentIds]);

For(Object2__c obj2 : trigger.new){
Id parentOwnerId = idObj1Map.get(obj2.Object1__c).OwnerId;

if(obj2.OwnerId != parentOwnerId ){ //diff owner

   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
   string body = 'Hi ';    
       mail.setSubject(obj2.Name + ' is the related list of ' + obj1.Name );  
       mail.setTargetObjectId(parentOwnerId);  
       mail.setSaveAsActivity(false);  
       mail.setHtmlBody(body);  
       mails.add(mail);  
    }
    }
    Messaging.sendEmail(mails);  
    }

Alternatively you could stamp the parent record owner Id on the related record via a before trigger and then use a workflow email alert to actually send out the email.


Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4288

My Block Status

My Block Content