0

I am finding it difficult to resolve the error. Any insights would be helpful. It is showing error for this line String[] bccEmail = new String[]{opp.owner.email}; in the below code.

global class memberapproval2{

    webservice static boolean callApproval(Id localId) { 

         if(localId != null){

         List<opportunity> opp =[select id,owner.email,RSM_Shipping_Contact__c,RSM_Shipping_Contact__r.Email from opportunity where Id =:localId];


         if(opp.size()>0){

         List<String> EmailIds = new List<string>();
         if(opp[0].owner.email != null){
         EmailIds.add(opp[0].owner.email);
         }
         if(opp[0].RSM_Shipping_Contact__r.Email != null){
         EmailIds.add(opp[0].RSM_Shipping_Contact__r.Email);
         }

           //New instance of a single email message
             Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

            // Who you are sending the email to

               mail.setToAddresses( EmailIds  );
            String templateIdVal= Label.TemplateId;
            String[] bccEmail = new String[]{opp.owner.email};
               // The email template ID used for the email
               mail.setTemplateId(templateIdVal);
               mail.setTargetObjectId(userinfo.getuserid());      
               mail.setWhatId(localId);   

               mail.setBccSender(true);
               mail.setBccAddresses(bccEmail);
               mail.setUseSignature(false);
               mail.setReplyTo(opp.owner.email);
               mail.setSenderDisplayName('Confirmation of Order Quote');
               mail.setSaveAsActivity(false);  

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

         }

        return true;  
    }
        return false;
    }
}
5

opp is an array, and you're trying to use it like a single record.

You actually meant to write:

String[] bccEmail = new String[]{opp[0].owner.email};
3

Its usually best to use plural names for collections and singular names for individual instances:

List<opportunity> opps = [select ... from opportunity where Id =:localId];
if(opps.size() > 0) {
    opportunity opp = opps[0];
    List<String> EmailIds = new List<string>();
    if (opp.owner.email != null) {
        ...

as its common to be dealing with both in code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.