• Terry Wyman
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
I am trying to deploy a simple invocablemethod class to send emails out when a lead is added to a campaign.  I had used hard coded IDs which provided 100% coverage in the sandbox but 0% in production, I've removed the hardcoded references.  Any help is appreciated, my code and test class are below:
public class SendEmailToLead {
    @InvocableMethod
    public static void sendEmail(List<CampaignMember> CampaignMembers) {
        List<CampaignMember> thecampaignmembers = new List<Campaignmember>();
        for (CampaignMember cm : CampaignMembers) {
            List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setTargetObjectId(cm.LeadId);
            List<String> sendTo = new List<String>();
            sendTo.add(cm.Email);
            mail.setToAddresses(sendTo);            
            mail.setReplyTo('nomail@nomail.com');
            mail.setSenderDisplayName('nomail');       
            
           Campaign c = [SELECT Id FROM Campaign WHERE Name = 'some name' LIMIT 1];
       		 if(cm.CampaignId == c.Id) {
		    		EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'some name' LIMIT 1];
                    mail.setTemplateId(et.id);
                 	List<String> bccTo = new List<String>();
           			bccTo.add('nomail@nomail.com');
                 	bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		mail.setBccAddresses(BccTo);
            }            
            Campaign c2 = [SELECT Id FROM Campaign WHERE Name = 'some name' LIMIT 1];
       		 if(cm.CampaignId == c2.Id) {
		    		EmailTemplate et2=[Select id from EmailTemplate where DeveloperName=:'some name' LIMIT 1];
                    mail.setTemplateId(et2.id);
                 	List<String> bccTo = new List<String>();
           			bccTo.add('nomail@nomail.com');                 	
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		mail.setBccAddresses(BccTo);
            } 
            mails.add(mail);
            Messaging.sendEmail(mails);                 
        }          
    }         
}
and the test class is below:
@isTest
// Tests the SendEmailToLead Trigger
public class TestSendEmailToCampaignMember {
static testMethod void ValidateSendEmailToCampaignMember() {
        Lead l = new Lead();
        l.FirstName = 'Testing';
        l.LastName = 'Lead';
        l.Company = 'Test Company';
        l.Industry = 'Banking';
        l.LeadSource = 'some source';
        l.Rating = 'Normal';
        l.Email = 'test@nomail.com';
        l.Street = '123 Main St';
        l.State = 'FL';
        l.PostalCode = '34202';
        l.Lead_Date__c = date.today();
        l.HasOptedOutOfEmail = False;
    	l.Internal_Comments__c = 'x';
    	l.Project_Details__c = 'x';
        insert l;             
        
    	Campaign c = new Campaign();
    	c.Name = 'some name';
    	c.Status = 'Planning';
    	c.Type = 'Seminar/Conference';
    	c.StartDate = date.today();
    	c.EndDate = date.today();
    	c.OwnerId = UserInfo.getUserId();
    	insert c;
    	 
      	CampaignMember cm = new CampaignMember();
    	cm.CampaignId = c.Id;
      	cm.LeadId = l.Id;    	
        cm.Status = 'Sent';
        insert cm;
        
        Lead l2 = new Lead();
        l2.FirstName = 'Testing2';
        l2.LastName = 'Lead2';
        l2.Company = 'Test Company2';
        l2.Industry = 'Banking';
        l2.LeadSource = 'some source';
        l2.Rating = 'Normal';
        l2.Email = 'test@nomail.com';
        l2.Street = '123 Main St';
        l2.State = 'FL';
        l2.PostalCode = '34202';
        l2.Lead_Date__c = date.today();
        l2.HasOptedOutOfEmail = False;
   		l2.Internal_Comments__c = 'x';
    	l2.Project_Details__c = 'x';
        insert l2;
    
    	Campaign c2 = new Campaign();
    	c.Name = 'some name';
    	c.Status = 'Planning';
    	c.Type = 'Seminar/Conference';
    	c.StartDate = date.today();
    	c.EndDate = date.today();
    	c.OwnerId = UserInfo.getUserId();
    	insert c2;
        
    	CampaignMember cm2 = new CampaignMember();
        cm2.LeadId = l2.Id;    	
        cm2.CampaignId = c2.Id;
        cm2.Status = 'Sent';
        insert cm2;
    }
}

I am hoping that it is something simple that I've missed.
I am trying to deploy a simple invocablemethod class to send emails out when a lead is added to a campaign.  I had used hard coded IDs which provided 100% coverage in the sandbox but 0% in production, I've removed the hardcoded references.  Any help is appreciated, my code and test class are below:
public class SendEmailToLead {
    @InvocableMethod
    public static void sendEmail(List<CampaignMember> CampaignMembers) {
        List<CampaignMember> thecampaignmembers = new List<Campaignmember>();
        for (CampaignMember cm : CampaignMembers) {
            List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setTargetObjectId(cm.LeadId);
            List<String> sendTo = new List<String>();
            sendTo.add(cm.Email);
            mail.setToAddresses(sendTo);            
            mail.setReplyTo('nomail@nomail.com');
            mail.setSenderDisplayName('nomail');       
            
           Campaign c = [SELECT Id FROM Campaign WHERE Name = 'some name' LIMIT 1];
       		 if(cm.CampaignId == c.Id) {
		    		EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'some name' LIMIT 1];
                    mail.setTemplateId(et.id);
                 	List<String> bccTo = new List<String>();
           			bccTo.add('nomail@nomail.com');
                 	bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		mail.setBccAddresses(BccTo);
            }            
            Campaign c2 = [SELECT Id FROM Campaign WHERE Name = 'some name' LIMIT 1];
       		 if(cm.CampaignId == c2.Id) {
		    		EmailTemplate et2=[Select id from EmailTemplate where DeveloperName=:'some name' LIMIT 1];
                    mail.setTemplateId(et2.id);
                 	List<String> bccTo = new List<String>();
           			bccTo.add('nomail@nomail.com');                 	
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		bccTo.add('nomail@nomail.com');
            		mail.setBccAddresses(BccTo);
            } 
            mails.add(mail);
            Messaging.sendEmail(mails);                 
        }          
    }         
}
and the test class is below:
@isTest
// Tests the SendEmailToLead Trigger
public class TestSendEmailToCampaignMember {
static testMethod void ValidateSendEmailToCampaignMember() {
        Lead l = new Lead();
        l.FirstName = 'Testing';
        l.LastName = 'Lead';
        l.Company = 'Test Company';
        l.Industry = 'Banking';
        l.LeadSource = 'some source';
        l.Rating = 'Normal';
        l.Email = 'test@nomail.com';
        l.Street = '123 Main St';
        l.State = 'FL';
        l.PostalCode = '34202';
        l.Lead_Date__c = date.today();
        l.HasOptedOutOfEmail = False;
    	l.Internal_Comments__c = 'x';
    	l.Project_Details__c = 'x';
        insert l;             
        
    	Campaign c = new Campaign();
    	c.Name = 'some name';
    	c.Status = 'Planning';
    	c.Type = 'Seminar/Conference';
    	c.StartDate = date.today();
    	c.EndDate = date.today();
    	c.OwnerId = UserInfo.getUserId();
    	insert c;
    	 
      	CampaignMember cm = new CampaignMember();
    	cm.CampaignId = c.Id;
      	cm.LeadId = l.Id;    	
        cm.Status = 'Sent';
        insert cm;
        
        Lead l2 = new Lead();
        l2.FirstName = 'Testing2';
        l2.LastName = 'Lead2';
        l2.Company = 'Test Company2';
        l2.Industry = 'Banking';
        l2.LeadSource = 'some source';
        l2.Rating = 'Normal';
        l2.Email = 'test@nomail.com';
        l2.Street = '123 Main St';
        l2.State = 'FL';
        l2.PostalCode = '34202';
        l2.Lead_Date__c = date.today();
        l2.HasOptedOutOfEmail = False;
   		l2.Internal_Comments__c = 'x';
    	l2.Project_Details__c = 'x';
        insert l2;
    
    	Campaign c2 = new Campaign();
    	c.Name = 'some name';
    	c.Status = 'Planning';
    	c.Type = 'Seminar/Conference';
    	c.StartDate = date.today();
    	c.EndDate = date.today();
    	c.OwnerId = UserInfo.getUserId();
    	insert c2;
        
    	CampaignMember cm2 = new CampaignMember();
        cm2.LeadId = l2.Id;    	
        cm2.CampaignId = c2.Id;
        cm2.Status = 'Sent';
        insert cm2;
    }
}

I am hoping that it is something simple that I've missed.
I created a process builder flow for an email alert and added it to our package. When I tried to deploy the change to another developer org (using ant), I'm encountering the below error.

[sf:deploy] -----------------------------------------------------------------------------------
[sf:deploy] Component Failures:
[sf:deploy] 1.  flows/Complaint_Email_Notification-8.flow -- Error: myRule_1_A1 (Action Call) - We can't find an action with the name and action type that you specified.
[sf:deploy] -----------------------------------------------------------------------------------

I came across this know issue that seems like the same issue I'm facing, but says it's fixed.
https://success.salesforce.com/issues_view?id=a1p300000008Y2MAAU

Seems like the myRule_1_A1 is the API name given to the flow components in the background.

Has anyone run into this issue?