You need to sign in to do that
Don't have an account?
![mirza OSAMA mirza OSAMA](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
how did u pickup the owner id of custom object to send mail in apex salesforce?
how did u pickup the owner id of custom object to send mail in apex salesforce?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
In the code you need to querry on the user object and get the email id value for sending email
public static void method2(list<Opportunity>newlist,Map<id,opportunity>oldmap){
try{
// list<messaging.email>emaillist=new list<Messaging.email>();
map<id,opportunity>oppmap=new map<id,opportunity>();
for(opportunity opp:newlist){
// Opportunity opp=new Opportunity();
// try{
if(oldmap!=null && opp.StageName!=oppmap.get(opp.id).stagename && opp.StageName=='Closed won'){
oppmap.put(opp.ownerid,opp);
// }catch(NullpointerException e){
System.debug('error');
// }
}
}
list<User> userlist=[select id,Email,Name from User where id in:oppmap.keyset()];
list<Messaging.Email>emails=new list<Messaging.email>();
Map<id,String>usermap=new map<id,String>();
for(User u:userlist) {
// if(oppmap.conatinskey(u.id){
usermap.put(u.id,u.email);
System.debug('mirza');
// }
}
Messaging.SingleEmailMessage msg=new Messaging.SingleEmailMessage();
for(User u : userList){
list <String> toadd=new LIST<String>();
String e1=usermap.get(u.id);
toadd.add(e1);
msg.setToAddresses(toadd);
msg.setSubject('Test subject');
// msg.setToAddresses(List<String> param1)
msg.setPlainTextBody('test body');
// messaging.email emaillist[]=new Messaging.email();
emails.add(msg);
}
Messaging.sendEmail(emails);
}
catch(exception e){
System.debug(e.getMessage());
}
}
}
------------
trigger trigopp on Opportunity (after update) {
if(Trigger.isUpdate && Trigger.isAfter){
Test.method2(Trigger.old,Trigger.oldMap);
}
}