I have a trigger code:
Trigger AutoEmailsending on Order (after update)
{
Map<Id,Order> Orderdetail = new Map<Id,Order>();
Set<Id> Accountid = new Set<Id>();
for(order or1 : Trigger.new)
{
if(or1.Status == 'Submitted' && (or1.Subtype__c =='Offer' || or1.Subtype__c =='ASP'))
{
Orderdetail.put(or1.id,or1);
Accountid.add (or1.accountid);
}
}
List<Attachment> Attachmentlst = [Select Id,
ParentId,
Name,
BodyLength,
Body,
Description
From Attachment
where ParentId=:Orderdetail.keyset()];
Map<Id,Account> Accountmap = New Map<Id,account>([Select id,
Name,
Email_Address__c,
Market__c,
JDE_ship_to_account_no__c
from account
where id in:accountid]);
Map<String, Blob> resources = new Map<String, Blob>();
for(StaticResource resource:[SELECT Name, Body FROM StaticResource where Name IN ('TC_for_France','TC_for_Italy')])
{
resources.put(resource.Name, resource.Body);
}
User currentUser = [Select Id,Phone,name from User where Id =:System.UserInfo.getUserId()];
for (attachment attachmentlst1 : attachmentlst )
{
List<String> Toaddress = new List<String>();
List<String> CCaddress = new List<String>();
String Orderid = attachmentlst1.ParentId;
String ResourceName;
String TCname;
string strHtmlBody;
String Emailaddress = UserInfo.getUserEmail();
String CustomerServiceEmail = Order_Configuration__c.getInstance().Customer_Service_Email__c;
string SellingOfficePhone = Order_Configuration__c.getInstance().Selling_Office_Phone__c;
String OrderNumber = Orderdetail.get(attachmentlst1.ParentId).OrderNumber;
List<Messaging.Emailfileattachment> fileAttachments = new List <Messaging.Emailfileattachment>();
if(Accountmap.get(Orderdetail.get(attachmentlst1.ParentId).accountid).Email_Address__c != null)
{
Toaddress.add(Accountmap.get(Orderdetail.get(attachmentlst1.ParentId).accountid).Email_Address__c);
}
String Market = Accountmap.get(Orderdetail.get(attachmentlst1.ParentId).accountid).Market__c;
CCaddress.add(emailaddress);
if(CustomerServiceEmail !=null)
CCaddress.add(CustomerServiceEmail);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(Toaddress);
mail.setCcAddresses(CCaddress);
if(Orderdetail.get(attachmentlst1.ParentId).Subtype__c =='Offer' || Market=='FR')
{
mail.setSenderDisplayName('Trade Order-FR');
ResourceName = 'TC_for_France';
TCname = 'CONDITIONS_GENERALES_DEVENTE.pdf';
}
else
{
mail.setSenderDisplayName('Trade Order-IT');
ResourceName = 'TC_for_Italy';
TCname = 'Condizioni_generali_di_vendita.pdf';
mail.setSubject('ORDINE ONETOUCH '+(AccountMap.get(Orderdetail.get(attachmentlst1.ParentId).accountid).Name));
}
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(attachmentlst1.Name);
efa.setBody(attachmentlst1.Body);
fileAttachments.add(efa);
Messaging.Emailfileattachment efa1 = new Messaging.Emailfileattachment();
efa1.setFileName(TCname);
efa1.setBody(resources.get(resourceName));
fileAttachments.add(efa1);
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
The above trigger code should send mail for created user for particular order, the mail should not send to last modified by user of particular order what i have to add the code for changes in my trigger code For created user only