function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
BUSYB0YBUSYB0Y

You cant do this using a workflow and email alert?

souvik9086souvik9086

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.setToAddresses(toAddresses);

			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.

Thanks