+ Start a Discussion
Chinmay AbhangraoChinmay Abhangrao 

Hello i Want the Email Id of Account Owner who owns the Particular case.... how can i do this? any soql query?

 If(Trigger.isinsert && Trigger.isafter){
    set<id> setid=new set<id>();
    for(Case c:trigger.new )
    {
       setid.add(c.AccountId);    
    } 
    list<account> acctoup=new list<account>();
    map<id,Account> acclist=new map<id,Account>([select id,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id=:setid]);
 
        for(Case c:trigger.new)
        {
        account a=acclist.get(c.AccountId);
            account a=acclist.get(c.AccountId);
           String EmailIdOfOwner =[SELECT Account.Owner.Email FROM Case WHERE c.id =a.Id]; // Something Wrong here  
        }
 
Best Answer chosen by Chinmay Abhangrao
Akshay_DhimanAkshay_Dhiman

Hi

Chinmay Abhangrao

Try this code
If(Trigger.isinsert && Trigger.isafter){
    set<id> setid=new set<id>();
    for(Case c:trigger.new )
    {
        if(c.AccountId!=null){
            setid.add(c.AccountId);
        }
           
    }
    if(setid.size() > 0){
    list<account> acctoup=new list<account>();
    map<id,Account> acclist=new map<id,Account>([select Owner.Email,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id IN:setid]);
 
        for(Case c:trigger.new)
        {
        
            String EmailIdOfOwner =acclist.get(c.AccountId).Owner.Email;
        }
    }
}


 
if you found this answer helpful then please mark it as best answer so it can help others.      
  
  Thanks 
  Akshay

All Answers

Akshay_DhimanAkshay_Dhiman

Hi

Chinmay Abhangrao

Try this code
If(Trigger.isinsert && Trigger.isafter){
    set<id> setid=new set<id>();
    for(Case c:trigger.new )
    {
        if(c.AccountId!=null){
            setid.add(c.AccountId);
        }
           
    }
    if(setid.size() > 0){
    list<account> acctoup=new list<account>();
    map<id,Account> acclist=new map<id,Account>([select Owner.Email,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id IN:setid]);
 
        for(Case c:trigger.new)
        {
        
            String EmailIdOfOwner =acclist.get(c.AccountId).Owner.Email;
        }
    }
}


 
if you found this answer helpful then please mark it as best answer so it can help others.      
  
  Thanks 
  Akshay
This was selected as the best answer
Chinmay AbhangraoChinmay Abhangrao
  how can we use this in email sending process?
;     /EmailSentToOwnert is class contains all the information required for the email                                                                                                              //sending process but it required an email address, subject, body ..can we pass this                                                                                                             //emailidOwner to this method.    
              EmailSendToOwner obj=new EmailSendToOwner()
               String EmailIdOfOwner =acclist.get(c.AccountId).Owner.Email;
             obj.sendMail(EmailIdOfOwner, 'subject', 'body');
PawanKumarPawanKumar
I have tried below and working fine for me. You also try this will work for you.

List<Case> caseList = [Select Id,Account.Owner.Email from Case];
for(Case eachCase : caseList){
System.debug('caseList:'+eachCase.Account.Owner.Email);
}

So for you just need to add the following to get the value of email. You no need to do an extra query. NOTE: make sure account owner has email populated in his record.
String EmailIdOfOwner = = c.Account.Owner.Email;

Please mark it best if it helps you. Thanks in advance.

Regards,
Pawan Kumar

 
Chinmay AbhangraoChinmay Abhangrao
How to add a custom setting for this trigger? I want to make one checkbox which is used when we want to deactivate our trigger when it is in production org..can anybody suggest how to it?
Akshay_DhimanAkshay_Dhiman
Please follow these steps:
// Step 1: Create a new Email
      Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
   
      // Step 2: Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(con.email);
      mail.setToAddresses(sendTo);
   
      // Step 3: Set who the email is sent from
      mail.setReplyTo('utkarsha.up10@gmail.com');
      mail.setSenderDisplayName('Utz patil');
   
      // (Optional) Set list of people who should be CC'ed
      List<String> ccTo = new List<String>();
      ccTo.add('puja.patil@aress.com');
      mail.setCcAddresses(ccTo);
 
      // Step 4. Set email contents - you can use variables!
      mail.setSubject('URGENT BUSINESS PROPOSAL');
      String body = 'Dear ' + con.FirstName;
     
      mail.setHtmlBody(body);
   
      // Step 5. Add your email to the master list
      mails.add(mail);
        Messaging.sendEmail(mails);
    }
  }
  // Step 6: Send all emails in the master list


if you find this answer helpful then please mark it as best answer so it can help others.
Thanks Akshay