• Ram Srivastav
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Salesforce developer
  • Accenture

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 1
    Questions
  • 4
    Replies
Receiving 2 x initial mail instead of one
Description Hi, I have written a trigger based workflow which will send one acknowledgment to the Customer with an template. Problem is same mail is sending twice to the customer. Anyone help me to get it solve. It will be highly appreciated.
please see the code snippet

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
    Public Static Boolean FinalEmail =false;
   
    for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Send_Email_to_Contact__c != c.Send_Email_to_Contact__c)) && (c.Send_Email_to_Contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status!='Completed')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
       
       
        if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Status != c.Status)) && (c.Final_email_to_contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status=='Completed')) {
               
                system.debug('****************'+c.Send_Email_to_Contact__c);
               
                sendFinalEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c);
        }
       
   
    }
   
    public void sendEmailMessage(String CaseId,String ConId,String internalComments,String EmailOfComplaint,String SiteDetail,String CaseNumber,String CustRef){
           
            Messaging.reserveSingleEmailCapacity(2);

            // Processes and actions involved in the Apex transaction occur next,
            // which conclude with sending a single email.
           
            // Now create a new single email message object
            // that will send out a single email to the addresses in the To, CC & BCC list.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           
            // Strings to hold the email addresses to which you are sending the email.
           
            String[] toAddresses = new String[] {EmailOfComplaint};
          //  String[] ccAddresses = new String[] {'koushik.saha@wipro.com'};
            String[] BccAddresses = new String[] {'Opsinvestigationteam@thameswater.co.uk'}; 
           
            // Assign the addresses for the To and CC lists to the mail object.
            mail.setToAddresses(toAddresses);
          //  mail.setCcAddresses(ccAddresses);
            mail.setBccAddresses(BccAddresses);
           
            // Specify the address used when the recipients reply to the email.
            mail.setReplyTo('OnlineCustomers@thameswater.co.uk');
           
            // Specify the name used as the display name.
            mail.setSenderDisplayName('OnlineCustomers@thameswater.co.uk');
           
            // Specify the subject line for your email address.
            mail.setSubject('Case Customer reference :'+CustRef+ ': Site Address :'+ SiteDetail + ': Query Number :'+CaseNumber);
           
            // Set to True if you want to BCC yourself on the email.
            mail.setBccSender(false);
           
            // Optionally append the salesforce.com email signature to the email.
            // The email address of the user executing the Apex Code will be used.
            mail.setUseSignature(false);
           
            // Specify the text content of the email.
            //mail.setPlainTextBody('Your Case: ' + case.Id +' has been created.');

          //  mail.setTargetObjectId('003P000000ZdOsB');
            mail.setWhatId(CaseId);
          //  mail.setTemplateId('00XP0000000I3cA');
           
           
            mail.setHtmlBody('<table><tr><td><img align="right" src="https://c.cs4.content.force.com/servlet/servlet.ImageServer?'+
            'id=015P00000000x8T&oid=00DP00000006dHM"/></td></tr><tr><td><br/><p><span style="font-family: Calibri;font-size=12pt;">'+
            '<font color="#333333">Dear Sir/Madam,</font></span></p>'+
            '<p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">Thank you for your enquiry on the above '+
            'address.</font></span></p><p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">'+
            'We would like to confirm that this query is currently being investigated and we will respond within 5 working days. '+
            '</font></span></p><p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">In the meantime, if you need anything further please contact '+
            'us on 0845 070 9148 and our team will be happy to help.</font></span></p></td></tr><tr><td><br/><br/><br/><br/></td></tr>'+
            '<tr><td><img src="https://c.cs4.content.force.com/servlet/servlet.ImageServer?id=015P00000000qUj&oid=00DP00000006dHM"/></td></tr></table>');

     //            'To view your case <a href=https://na1.salesforce.com/'+case.Id+'>click here.</a>');
    
       
            // Send the email you have created.
            if(!Test.IsRunningTest())
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

       
        }
       
     public void sendFinalEmailMessage(String CaseId,String ConId,String internalComments, String EmailOfComplaint,String SiteDetail,String CaseNumber,String CustRef){
           
            if(internalComments==null){
            internalComments='';
            }
            Messaging.reserveSingleEmailCapacity(2);

            // Processes and actions involved in the Apex transaction occur next,
            // which conclude with sending a single email.
           
            // Now create a new single email message object
            // that will send out a single email to the addresses in the To, CC & BCC list.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           
            // Strings to hold the email addresses to which you are sending the email.
            String[] toAddresses = new String[] {EmailOfComplaint};
       //     String[] ccAddresses = new String[] {'koushik.saha@wipro.com'};
            String[] BccAddresses = new String[] {'Opsinvestigationteam@thameswater.co.uk'}; 
           
            // Assign the addresses for the To and CC lists to the mail object.
            mail.setToAddresses(toAddresses);
         //   mail.setCcAddresses(ccAddresses);
            mail.setBccAddresses(BccAddresses);
           
            // Specify the address used when the recipients reply to the email.
            mail.setReplyTo('OnlineCustomers@thameswater.co.uk');
           
            // Specify the name used as the display name.
            mail.setSenderDisplayName('OnlineCustomers@thameswater.co.uk');
           
            // Specify the subject line for your email address.
            mail.setSubject('Case Customer reference :'+CustRef+ ': Site Address :'+ SiteDetail + ': Query Number :'+CaseNumber);
           
            // Set to True if you want to BCC yourself on the email.
            mail.setBccSender(false);
           
            // Optionally append the salesforce.com email signature to the email.
            // The email address of the user executing the Apex Code will be used.
            mail.setUseSignature(false);
           
            // Specify the text content of the email.
            //mail.setPlainTextBody('Your Case: ' + case.Id +' has been created.');

       //     mail.setTargetObjectId('003P000000ZdOsB');
            mail.setWhatId(CaseId);
       //     mail.setTemplateId('00XP0000000I3cA');
           
           
       
mail.setHtmlBody('<table><tr><td><img align="right" src="https://c.cs4.content.force.com/servlet/servlet.ImageServer?'+
            'id=015P00000000x8T&oid=00DP00000006dHM"/></td></tr><tr><td><br/><p><span style="font-family: Calibri;font-size=12pt;">'+
            '<font color="#333333">Dear Sir/Madam,</font></span></p>'+
            '<p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">Further to your enquiry on the above address.'+
            '</font></span></p><p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">'+
            'We\'ve completed our investigations and can provide the following response: '+
            '</font></span></p><p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">'+internalComments+'</font>'+
            '</font></span></p><p><span style="font-family: Calibri;font-size=12pt;"><font color="#333333">If you have any further questions please contact us on 0845 070 9148.</font></span></p></td></tr><tr><td><br/><br/><br/><br/></td></tr>'+
            '<tr><td><img src="https://c.cs4.content.force.com/servlet/servlet.ImageServer?id=015P00000000qUj&oid=00DP00000006dHM"/></td></tr></table>');


          
            // Send the email you have created.
            if(!Test.IsRunningTest())
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

       
        }
}
Hi,

I have defined Apex triggers on after insert which will fire the email on per case basis. Issue is same email is firing twice. Could any one help to get it solve..

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
  
     for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Send_Email_to_Contact__c != c.Send_Email_to_Contact__c)) && (c.Send_Email_to_Contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status!='Completed')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
}       
       
       
trigger abcAccount on Opportunity (before update) {
    list<id> oppIds = new list<id>();
    //if(trigger.isInsert || trigger.isUpdate){
        for(opportunity opp : trigger.new){
            system.debug('opp'+opp);
            system.debug('opp.Account.name'+opp.Account.name);
            if(opp.Account.name=='Axis'){
             system.debug('opp'+opp);
                opp.amount = opp.amount*10/100;
                //oppIds.add(opp.id);
            }
        }
    //}

}

Hi I am getting null for opp.Account.name when ued system.debug('opp.Account.name'+opp.Account.name);
 Actually iam trying to disount on amount when related account of the opportunity is changed to Axis.
Can some one help me on this?
 
Hi Friends,

how to  salesforce WSDL or Rest  API Url creating please Help me

Thanks 
kullai
Hi,

I have defined Apex triggers on after insert which will fire the email on per case basis. Issue is same email is firing twice. Could any one help to get it solve..

trigger sendEmail on Case (after insert,after update) {
    Public static Boolean InitialEmail =false;
  
     for(Case c:trigger.new) {
       
        system.debug('outside'+c.Send_Email_to_Contact__c);
       
        if ((trigger.isInsert || (trigger.oldMap.get(c.Id).Send_Email_to_Contact__c != c.Send_Email_to_Contact__c)) && (c.Send_Email_to_Contact__c && !c.Do_not_Send_Email__c  && c.Email_of_Complainant__c!=null && c.Status!='Completed')) {
               
                system.debug('??????'+c.Send_Email_to_Contact__c);
              
                    sendEmailMessage(c.id,c.ownerId,c.Internal_Comments__c,c.Email_of_Complainant__c,c.Site_Details__c,c.CaseNumber,c.Case_Customer_Reference__c );
        }
       
}       
       
       

Hi Force Community,

 

      I have a question. Not sure if I am suppose to post this in Visual force developement or Apex code development so here goes. I am doing some javascript remoting to call some method in my controller. The code works when I am in developer mode but when i turn that off it shows this  warning message : "Javascript proxies were not generated for controller mobileController2 : may not use public remoted methods inside an iframe". I gave it to my co-worker and it does not matter if he is in developer mode or not. I looked around and changed the controller to global as well as as make the remote action method that I am calling global. To do the javascript remoting I tried that short hand and the full name space as well, but still nothing. It should be noted that I have other javascript remoting in my code and those works fine, but those one does not have to do anything with iframe. Any help or suggestion would be greatly appreciated.