• CW83
  • NEWBIE
  • 25 Points
  • Member since 2013
  • Technology Supervisor
  • ProEdit, Inc


  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
We had a developer write an apex plugin to use in a flow but he didn't write any test for code and now my overall code coverage is less than 75% so I can't deploy anything via a changeset.  Below is the code.  Any help is appreciated.

global class mLSendEmail implements Process.Plugin {
    
    global Process.PluginResult invoke(Process.PluginRequest request) { 
        
        // Get the subject of the Chatter post from the flowgj
        //String emailS = (String) request.inputParameters.get('emailListString');
        String campaignId = (String) request.inputParameters.get('campaignId');
        String tempId = (String) request.inputParameters.get('emailTempId');
        //system.debug(idS);
        String userIdVar = UserInfo.getUserId();
        //List<String> emailList = emailS.split(', ');
        
        User userObject = [SELECT Name, Email
                           FROM User
                           WHERE Id = :userIdVar.left(15)
                           LIMIT 1]; //(String) request.inputParameters.get('userName');
        
        List<CampaignMember> test = [SELECT ContactId, CampaignId
                                     FROM CampaignMember
                                     WHERE CampaignId = :campaignId];
        
        List<Contact> contacts = [SELECT Id, Name, Email 
                                  FROM Contact 
                                  WHERE Id IN (SELECT ContactId 
                                               FROM CampaignMember 
                                               WHERE CampaignId = :campaignId AND ContactId != null)
                                  ];
        
        List<Lead> leads = [SELECT Id, Name, Email 
                            FROM Lead
                            WHERE Id IN (SELECT LeadId 
                                         FROM CampaignMember 
                                         WHERE CampaignId = :campaignId AND LeadId != null)
                            ];
        system.debug('EMAIL TEMPLATE ID: ' + tempId);
        system.debug('VALUE OF CONTACTS: ' + contacts);
        List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
        if (!contacts.isEmpty()) {
            system.debug('mLSendEmail.cls - contacts != null');
            for (integer i = 0; i <= contacts.size()-1; i++) {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateId(tempId);
                mail.setReplyTo(userObject.Email);
                mail.setSenderDisplayName(userObject.Name);
                mail.setTargetObjectId(contacts.get(i).Id);
                mails.add(mail);
           }
        } else if (!leads.isEmpty()) {
            system.debug('mLSendEmail.cls - leads != null');
            for (integer i = 0; i <= leads.size()-1; i++) {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateId(tempId);
                mail.setReplyTo(userObject.Email);
                mail.setSenderDisplayName(userObject.Name);
                mail.setTargetObjectId(leads.get(i).Id);
                mails.add(mail);
            }
        } else {
            system.debug('mLSendEmail.cls - else');
        }
  Messaging.sendEmail(mails);
        
        
        
        
        // return to Flow
        Map<String,Object> result = new Map<String,Object>(); 
        return new Process.PluginResult(result); 
        
    } 
    
    global Process.PluginDescribeResult describe() { 
        Process.PluginDescribeResult result = new Process.PluginDescribeResult(); 
        result.Name = 'Marketing Email Plugin';
        result.Tag = 'ML Email';
        result.inputParameters = new 
           List<Process.PluginDescribeResult.InputParameter>{
               new Process.PluginDescribeResult.InputParameter('emailTempId',
               Process.PluginDescribeResult.ParameterType.STRING, true),
               new Process.PluginDescribeResult.InputParameter('campaignId',
               Process.PluginDescribeResult.ParameterType.STRING, true)
            };
        result.outputParameters = new 
           List<Process.PluginDescribeResult.OutputParameter>{ }; 
        return result; 
    }
}
I have a javascript button I am trying to create to update a picklist field on a custom object.  Here is the code for the button:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

var p = new sforce.SObject('Projects__c');
p.id = "{Projects__c.Id}";
p.Status__c = "Closed";
result = sforce.connection.update([p]);
location.reload(true);

The code is not throwing errors on the object it is just not updating the field.  The page is reloading. Anything wrong with the code?

Here is the error I am getting:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INACTIVE_OWNER_OR_USER, operation performed with inactive user: []", Failure Stack Trace: "Class.ChatterAnswers.createAccount: line 4, column 1 Class.ChatterAnswersCreateAccountTest.validateAccountCreation: line 10, column 1"

I am stumped.  I was able to validate and deploy from my dev sandbox to my UAT sandbox but now I get this error in production when I go to validate.   

I looked to see if I had any assignment rules that were trying to assign to an inactive user.  I also looked to make sure I didn't have any inactive users that are Chatter Answers users.  

Any ideas?

I've set up the Action Plans app, (https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003HcINEA0)

And following the documentation.

First up it would seem the documentation for setting up a Custom Object against the action plans is a bit out of date, but I can work around the slight differences there I believe.

 

However, I'm getting the following error when running tests. 

Class.ActionPlansBatchBuilderTest.runBatchException: line 316, column 1.

 

I thought this was down to some changes I had made being incorrect so I ran all tests on production. They passed.

I then refreshed the Sandbox, and once ready ran the tests there. And this error comes up immediately. 

 

Has anyone else encountered this problem with Action Plans, and found a work around?