+ Start a Discussion
Kondal Rao learnerKondal Rao learner 

urgent pls on trigger

Hi expert,


1.       Create a trigger on External Review object
2.       Whenever the status is “Review Submitted” trigger should fire and pick the Owner from the related opportunity(Lookup on External Review) and send a notification to Proposal Owner
 pls how to do that

You cant do this using a workflow and email alert?


Try this


trigger sendNotification on ExternalReview__c(after insert,after update){
Map<ID,ExternalReview__c> oppMap = new Map<ID,ExternalReview__c>([SELECT id,Opportunity__r.owner.name,Opportunity__r.Owner.Email FROM ExternalReview__c WHERE id in :Trigger.new]);
	for(ExternalReview__c exRev: Trigger.new){
		if(exRev.status == 'Review Submitted'){
			String ownerEmail = oppMap.get(exRev.id).Opportunity__r.Owner.Email;
			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

			String[] toAddresses = new String[] {ownerEmail};

			mail.setSubject('Notification Email : ' + trigger.new[0].Name);

			mail.setPlainTextBody('Owner of Opportunity: ' + oppMap.get(exRev.id).Opportunity__r.Owner.Name);
			mail.setHtmlBody('Owner of Opportunity: <b>' + oppMap.get(exRev.id).Opportunity__r.Owner.Name);

			Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.