• Scott Brady
  • NEWBIE
  • 45 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 10
    Replies
Hi Folks,

I require some assistance creating a test class for a trigger that I wrote. Any help would be greatly appreciated:
 
trigger SCHParseReceivedEmail on BMCServiceDesk__IncidentHistory__c (after insert){
    for (BMCServiceDesk__IncidentHistory__c action : trigger.new){    

            if(action.BMCServiceDesk__FKIncident__c != null){
                BMCServiceDesk__Incident__c ticket = [SELECT id, Customer_Reference_Number__c,BMCServiceDesk__Incident__c.Relationship_Name__c FROM BMCServiceDesk__Incident__c WHERE Id = :action.BMCServiceDesk__FKIncident__c];
                
                if(action.BMCServiceDesk__actionId__c == 'Email Received') {
                                    if(ticket.Relationship_Name__c == 'Random Customer Name') {
                        ticket.Customer_Reference_Number__c = action.BMCServiceDesk__description__c.substringBetween('##');
                            update Ticket;                
                }
           }    
    }

  }
}

Here are some required linkages between the objects being tested.

Incident History relies on an Incident to exist.  It receives emails and creates an incident history record.  I believe all I need to do in my test class is create an incident and an incident history record linked and verify that my trigger updated with the correct chracters located in between the ## delimiters in my substring.  I am having some issues getting a test class created and i think that I am probably overthinking things...

Here is what I have for my test class - currently getting an error Error: Compile Error: unexpected token: 'static' at line 16 column 5
 
@isTest(seeAllData=false)
Private class SCHParseReceivedEmailTest {

    public static List<Contact> contactsList;
    public static List<BMCServiceDesk__Incident__c> ticketsList;
    public static List<Account> accountsList;
    public static List<BMCServiceDesk__IncidentHistory__c> historyList;
    
    static void init(){
        contactsList = new List<Contact>();
        ticketsList = new List<BMCServiceDesk__Incident__c>();
        accountsList = new List<Account>();
        historyList = new List<BMCServiceDesk__IncidentHistory__c>();
        
    // Test Initiation
    static testMethod void testSCHParsingUpdater() {
    init();
    Test.startTest();
        
    // Create a test account, with test contact, as a requirement to create a new ticket (required fields)
    accountsList.add(new Account(
        Name = 'Random Customer Name',
        Type = 'Customer - Direct',
        Support_Level__c = 'Managed Services'
        ));
            Insert accountsList;
            
    contactsList.add(new Contact(
        LastName = 'SCH Testing',
        Phone = '5555555555',
        Email = 'test@testing.com',
        Account = [Select Id from Account where Name = 'Random Customer Name'].Id
        ));
            Insert contactsList;
    
    // Create a test ticket to be the updated record of the trigger
    ticketsList.add(new BMCServiceDesk__Incident__c(
        BMCServiceDesk__FKContact__c = [Select Id from Contact where LastName = 'SCH Testing'].Id,
        BMCServiceDesk__FKImpact__c = [Select Id from BMCServiceDesk__Impact__c where Name = '1-Enterprise-wide'].Id,   
        BMCServiceDesk__Urgency__c = [Select Id from BMCServiceDesk__Urgency__c where Name = '4 LOW'].Id,
        Customer_Reference_Number__c = 'SCH Testing',
        BMCServiceDesk__FKCategory__c = [Select Id from BMCServiceDesk__Category__c where Name = 'Request'].Id,
        BMCServiceDesk__shortDescription__c = 'Testing for SCH Parsing Updates'
        ));
            Insert ticketsList;
            
    // Create an Incident History record to be parsed by the ticket
    historyList.add(new BMCServiceDesk__IncidentHistory__c(
        BMCServiceDesk__FKIncident__c = [Select Id from BMCServiceDesk__Incident__c where Customer_Reference_Number__c = 'SCH testing'].Id,
        BMCServiceDesk__FKAction__c = [Select Id from BMCServiceDesk__Action__c where Name = 'Email Received'].Id,
        BMCServiceDesk__description__c = 'Email Received-SCH Internal Ticket Number##CHG0763071## Request Type##SCH Firewall Requests##',
        BMCServiceDesk__note__c = 'Email Received-SCH Internal Ticket Number##CHG0763071## Request Type##SCH Firewall Requests## (Ref:IN:01090698)'
        ));
            Insert historyList;
            }
            
    // Verify the trigger completed the customer reference field update
    ticketsList = [
        SELECT Id, Customer_reference_number__c
        FROM BMCServiceDesk__Incident__c
        WHERE Id = :ticketsList[0].Id
        ];
        
    // Verification
    System.asserEquals(ticketsList[0].Customer_reference_number__c, 'CHG0763071');
    
    Test.stopTest();
    }
}

 
Hi All,

I have the following, basic, inbound email handler class:
 
global class ProcessInboundEmailSupport implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

     BMCServiceDesk__Incident__c ticket = new BMCServiceDesk__Incident__c();   
        if([select count() from Account where Account.Support_Email_Service__c = :email.toAddresses] == 0) {

            }
            else {
                 ticket.BMCServiceDesk__FKAccount__c = [select Id from Account where Account.Support_Email_Service__c = :email.toAddresses].Id;
                 ticket.BMCServiceDesk__shortDescription__c = email.subject;
                 ticket.BMCServiceDesk__incidentDescription__c = email.plaintextbody;
                 ticket.BMCServiceDesk__FKContact__c = [select Id from Contact where contact.Email = :email.fromAddress].Id;
                 ticket.Source__c = 'Email';
                 ticket.BMCServiceDesk__FKCategory__c = 'a2kS0000000lg1Q';
                 ticket.Emailed_From__c = email.fromAddress;
                 }
          
    insert ticket;

    System.debug('====> Created ticket '+ticket.Id);
    
            
    BMCServiceDesk__IncidentHistory__c action = new BMCServiceDesk__IncidentHistory__c();
        action.BMCServiceDesk__FKAction__c = 'a0QS0000003wjRR';
        action.BMCServiceDesk__note__c = 'From:' +' '+ email.fromAddress +'\n'+ 'To:' +' '+ email.toAddresses +'\n'+ 'Cc:' +' '+ email.ccAddresses +'\n'+ 'Subject:' +' '+ email.subject +'\n'+ 'Body:' +' '+ email.plaintextbody;
        action.BMCServiceDesk__FKIncident__c = ticket.id;
            insert action;

    if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
      for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
        Attachment attachment = new Attachment();
        
        attachment.ParentId = ticket.Id;
        attachment.Name = email.binaryAttachments[i].filename;
        attachment.Body = email.binaryAttachments[i].body;
        insert attachment;
      }
    }

    return result;

  }

}

The class works just fine for me, however, when I am trying to create a test class, I keep receiving nullpoint exceptions - it's always line 24
 
@isTest
public class TestSupportHandler {
 public static testMethod void TestMyController() {

  // create a new email and envelope object
  Messaging.InboundEmail email = new Messaging.InboundEmail() ;
  Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

  // setup the data for the email
  email.subject = 'Test Email Subject';
  env.fromAddress = 'sbrady@digitalhands.com';

  // add an attachment
  Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfile.txt';
  attachment.mimeTypeSubType = 'text/plain';

  email.binaryAttachments =
    new Messaging.inboundEmail.BinaryAttachment[] { attachment };

  // call the email service class and test it with the data in the testMethod
  ProcessInboundEmailSupport emailProcess = new ProcessInboundEmailSupport();
  emailProcess.handleInboundEmail(email, env);

  // query for the ticket the email service created
  BMCServiceDesk__Incident__c ticket = [select id, Emailed_From__c  from BMCServiceDesk__Incident__c
    where Emailed_From__c = :env.fromAddress];

  System.assertEquals(ticket.Emailed_From__c,'sbrady@digitalhands.com');
 
  // find the attachment
  Attachment a = [select name from attachment where parentId = :ticket.id];

  System.assertEquals(a.name,'textfile.txt');

}
}

I have two questions:
1. Why am I receiving that error when I believe that variable is defined above on the previous line.
2. I am not the best with test classes, so I know that this will not test ALL of my class and I will need to add to it - however would this test class point me in the right direction? Or do I need to change quite a bit?

Any assistance that could be provided would be wonderful, I am still learning a bit about the test classes/requirements as I go.   
Hi All,

On 5/26/2017 I had created an email service within a new sandbox to test an email handler - everything was working just fine on that date. Then on 5/29/2017 I was no longer able to email the sandbox, receiving this error:

dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com (dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com)
Your message couldn't be delivered. The Domain Name System (DNS) reported that the recipient's domain does not exist.
Contact the recipient by some other means (by phone, for example) and ask them to tell their email admin that it appears that their domain isn't properly registered at their domain registrar. Give them the error details shown below. It's likely that the recipient's email admin is the only one who can fix this problem.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Diagnostic information for administrators:
Generating server: BY2PR11MB0613.namprd11.prod.outlook.com
dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com
Remote Server returned '550 5.4.310 DNS domain does not exist [Message=InfoDomainNonexistent] [LastAttemptedServerName=7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com] [CO1NAM03FT010.eop-NAM03.prod.protection.outlook.com]'

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Could this be at all related to our internal network? We didn't change antyhing..  Or does this seem like a Salesforce issue? I am surprised that within 3 days it worked and then stopped working.  Anyone have any idea or perhaps has experienced this problem before in their instance?

I reached out to support but was told that email services are a developer issue, not something support can offer assistance with (even though it's a standard functionality).  Last bit of info - no matter what I use for the apex class associated with the email service, i cannot send any emails into the sandbox.  All Email is also enabled within the sandbox.





 
Hi All,

I am in search of some assistance with helping me get a very simple controller into production.  I currently have 31% test coverage but I am running into issues confirming a page reference (and perhaps I may be missing something else to test to get to 75% coverage).  See my controller below:
 
public with sharing class dhrequestsInsertController
{
    public dhrequest__c requests {
        get {
            if(requests == null)
                requests = new dhrequest__c();
        return requests;
        }
        set;
   
    }
      
       
    public dhrequestsInsertController() {
    }
    
    public PageReference SubmitRequest() {
    try {
        insert requests;
        } catch (DMLException e) {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new request. Please contact the Business Intelligence Team.'));
      }
      PageReference detailPage = new PageReference('/' + requests.id);
      return detailPage;
}


    public PageReference CancelRequest() {
        PageReference pr = new PageReference('/apex/dhrequests');
        pr.setRedirect(true);
        return pr;
}
}

Now here is my current test class in progress, sitting at 31% coverage at the moment.  Any tips would be most appreciated! Thank you very much in advance.
 
@isTest
public class dhrequestsInsertControllerTest {

public static testMethod void dhrequestsInsertControllerTest() {


    PageReference pageRef = Page.dhrequestdiscovery;
        Test.setCurrentPage(pageRef);
        
    dhrequestsInsertController controller = new dhrequestsInsertController();
                    
    dhrequest__c r = new dhrequest__c(dh_businesscase__c='test', dh_errormessage__c='error', dh_workaround__c='workaround');
    System.debug('business case before inserting: ' + r.dh_businesscase__c);   
        Insert r;
    
    String nextPage = controller.SubmitRequest().getUrl();
        System.assertEquals('/' + dhrequest__c.id, nextPage);    
    
        
    r = [SELECT dh_businesscase__c, id, dh_errormessage__c, dh_workaround__c FROM dhrequest__c WHERE id =:r.Id];
        System.debug('business case after inserting: ' + r.dh_businesscase__c); 
        System.debug('error after inserting: ' + r.dh_errormessage__c);
        System.debug('workaround after inserting: ' + r.dh_workaround__c);   
         
                      
    System.assertEquals('test', r.dh_businesscase__c);
    System.assertEquals('error', r.dh_errormessage__c);
    System.assertEquals('workaround', r.dh_workaround__c);    
        
        
    String lastPage = controller.CancelRequest().getUrl();
        System.assertEquals('/apex/dhrequests', lastPage);
        
  
    }
}


the SubmitRequest() pageref is giving me fits because I need to confirm that the record that is inserted, it's record Id is contained in the submitrequest redirect (to the detail page of the customer object).  I am getting mismatches there.  I also do not know how to replicate the error message itself, since it's really a catch all.  Any ideas?  Thanks again in advance.
 

Best,
Scott

I currently have a button that is designed to allow our users to take ownership of their Incident (custom object, Remedyforce related) and put the status "In Progress".  This button is a custom detail page button that is located on the "record details" page of the console view.  Here is the code:
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
 
try{
var incidentToUpdate = new sforce.SObject("BMCServiceDesk__Incident__c");
 
/*
The next 3 lines of code select the incident to update (current page the user is on), selects the user to assign as the owner of the ticket (current user clicking the button) and updates the ticket status to "in progress"
*/
incidentToUpdate.Id = "{!BMCServiceDesk__Incident__c.Id}";
incidentToUpdate.OwnerId = "{!$User.Id}";
incidentToUpdate.BMCServiceDesk__FKStatus__c = "a4V80000000PBFi";
 
/*
this sets the variable for categoryId = Category ID on the ticket. This is done because we are selecting the category Id to input in the lookup field (category).
*/
 
var categoryId = "{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategoryId__c}";
 
/*
The next block of If/Else If statements are what reassigns the category. First if statement checks to see if the first letter of the category is an A, for 'Alert'. If so, it will update the categoryId (variable) to 'Incident'. Next, it will do the same check to see if the first letter is an I, for 'Incident', but will not change the category. The same for the next if statement, but for R and 'Request'
*/
if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(0) == 65
){
categoryId = "a2k80000000Gqyj";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(1) == 110
){
categoryId = "a2k80000000Gqyj";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(0) == 82
){
categoryId = "a2k80000000Gqyy";
}
else if(
"{!BMCServiceDesk__Incident__c.BMCServiceDesk__FKCategory__c}".charCodeAt(1) == 72
){
categoryId = "a2k340000008i8m";
}
incidentToUpdate.BMCServiceDesk__FKCategory__c = categoryId;
 
var result = sforce.connection.update([incidentToUpdate]);
 
if(result[0].success == "true"){
location.reload();
}
else{
alert(
"An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}


 
Ignore the notes that are included, as they are meant for my manager who may need to make edits to the button when i am not present.  My question is to figure out/ask if this can be changed into a visualforce page/action that can be invoked via the Custom Action feature within the Remedyforce Console (Remedyforce is an add-on to Salesforce). RIght now, Custom Actions needs to invoke a URL, and unfortunately, that's forcing me to change this button into a visualforce page that I could use for my URL.  I also know that I could perhaps "URL hack", but the Remedyforce console does not like that, as the URL hack redirects me back to the standard Incident object within Salesforce rather then than the Console view.  The button itself does work and does make the updates I want it to, but I'd like to have it as a custom action.
Any ideas?
I have this existing code
 
<apex:page standardController="BMCServiceDesk__Incident__c">

  <apex:sectionHeader title="SIEM - Account Event"/>
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save & Send Email"
            action="{!save}"/>
        <apex:commandButton value="Cancel"
            action="{!cancel}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="Account Event - Alarm Information"
          collapsible="false">
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Event_Action__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Alarm_Name__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Signature_ID__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Event_ID__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Source_IP__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Source_Port__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Host__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Destination_IP__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Destination_Port__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Source_User__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Modified_Object__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Modification__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Time_Date__c}"/>
        <apex:inputField value="{!BMCServiceDesk__Incident__c.Description__c}"/>        
      </apex:pageBlockSection>
     </apex:pageBlock>
  </apex:form>
</apex:page>

I wish to add additional functionality so that, after they click on the button to bring up the new page with fields to be filled out, I want them to have the option to select from a picklist of 3 options, which depending on the selection, will update the form to include either additional fields or remove fields.

So, in the example above, I want to add a field, we will call it Picklist__c for this exercise, and if they select Option 1 - then I want one set of fields to appear.  Option 2 - a different set of fields, etc.

The end goal is to remove the need to create multiple buttons.

Thanks,
Scott
Hi There,

I am trying to write an APEX Class to be scheduled every year on March 1st and September 1st at 12am that will go out and edit/save all records of a customer object (Personnel_Management__C). The reason for the requirement is that we have semi-annual audit that needs to be performed on our employee information. Nothing needs to be updated, but there is a process/flow behind the scenes that I want to have triggered so that the automated approval processes and other business processes that are included in the process run.  The only way I can see this happening is for an update to be made to each record that would require an audit - scheduled apex.

the customer object in question is Personnel_Management__C - At any given audit, 100+ records could qualify for the select statement for an update (keep in mind, I just want to edit and then save each record, not actually change any values).

The criteria to be met is that within Personnel_Management__C there is a picklist field that is called Employment_Status__C.  This field needs to be "Current Employee" in order for it to qualify for the select statement.

I really appreciate your time and effort to help me get this done - thanks in advance (I am hoping this is quite simple and will serve as a great learning experience for me).
Good morning, everyone

I have the following issue.

I am trying to create a JS button that will update a few fields on the current object, as well as make a few updates on two related objects.  Here is their relation:

Recruiting Position
Personnel Management ---related to--> Recruiting Position via lookup ID
User Provision Requests ---related to--> Personnel Management via lookup ID

so it works like this:  User Provision Requests --->  Personnel Management ---> Recruiting Position

What I am trying to do is place a button on the User Provision Requests page  that would access a field on the Recruiting Position page and make a change.  I have already been able to make the correct ID calls for update on the User Provision Request and Personnel Management objects, but I am not having any luck with the recruiting position field.  Here's my code, which should explain what I am trying to do:
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

try{
var PersonnelToUpdate = new sforce.SObject("Personnel_Management__c");
var PositionToUpdate = new sforce.SObject("Recruiting_Position__c");
var ProvisionToUpdate = new sforce.SObject("User_Provision_Request__c");

PersonnelToUpdate.Id = "{!User_Provision_Request__c.Employee__c}";
PersonnelToUpdate.Recruiting_Stage__c = "Former Employee";
PositionToUpdate.Id = "{Personnel_Management__r.Recruiting_Position__c.id}";
PositionToUpdate.Recruiting_Stage__c = "Open";
ProvisionToUpdate.Id = "{!User_Provision_Request__c.Id}";
ProvisionToUpdate.Provisioning_Request_Type__c = "Deactivate User Request Form (DURF)";

var result = sforce.connection.update([ProvisionToUpdate]);
var result = sforce.connection.update([PersonnelToUpdate]);
var result = sforce.connection.update([PositionToUpdate]);


if(result[0].success == "true"){
location.reload();
}
else{
alert(
"An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}

The Recruiting Position ID call is what is failing.  The personnel management and user provision requests calls/actions work just fine.  Any tips as to who I can call on a related field through a shared object?  I want to hop through a lookup field to an object that has an additional lookup field to have access to a 3rd object that contains the fields I want to update.

Your help is greatly appreciated!

Thank you in advance.

Scott
Good afternoon,

I have a strange problem going on within my production environment of Salesforce.  Here's the issue, then I will explain what my testing has discovered.

One of our customers was complaining that any of the emails that are manually being sent from our system (Action: Send Email) and where we select an HTML Template (can be any HTML template), the customer is receiving a blank email.  Specifically, they are receiving the base template, without the changes that were made prior to sending the email.  In other words, our tech selects an email template, populates information as needed, and off it goes.  The customer has said that they receive the template, but without the additional informaiton that was added.

Now, in the Activity History related list, the data there shows that the email went out fine, and that all the information that was added to the template is there.  When I send a test email using a template to my own internal and external email addreses, I receive the template with the additional information just fine. What I have noticed, however, is that if I were to CC an email-listener enabled email address on the intial send of the email with the template, Salesforce will append the email to the related case based off the (REF IN:XXXXXX) tag.  But, even though I know the message that is sent out contains additional information other than the base template (I also CC a personal email address to confirm), the email that gets appended back in Salesforce only contains the base template, no additional information. 

This is strange.  Because I have already confirmed that the correct email is sent out, but for some reason the receipt of the email that salesforce receives only records the template, no custom info. 

Further, it only happens when I use an HTML template specifically.  All Custom or Text templates function without any issues. It's only the HTML items.

Some Extra Detail to help clarify confusing bits:

IF, I send an email like so:

To:  Scott@emailaddress.com
CC: Scott@salesforce.api..... (etc) - Salesforce Email Service
Body:  <template> Test Information

The email that I receive at scott@emailaddress.com contains all the information.
The email the salesforce recieives at Scott@salesforce.api....(etc) does not have "test information", but rather just the base template.

To:  Scott@emailaddress.com
CC: Scott@salesforce.api....(etc)
Body:  <template>

ONLY for HTML templates, any ideas?  Salesforce support told me that I would have to come here for an answer. Not sure why, since it seems to be on their end since everything else about the email functionality is working without issue.  I have checked the debug logs, there's no issues with the email that is sent out (confirmed via debug log and also that I receive the email as well).

Thanks for your help,
Scott
 
Hi Folks,

I require some assistance creating a test class for a trigger that I wrote. Any help would be greatly appreciated:
 
trigger SCHParseReceivedEmail on BMCServiceDesk__IncidentHistory__c (after insert){
    for (BMCServiceDesk__IncidentHistory__c action : trigger.new){    

            if(action.BMCServiceDesk__FKIncident__c != null){
                BMCServiceDesk__Incident__c ticket = [SELECT id, Customer_Reference_Number__c,BMCServiceDesk__Incident__c.Relationship_Name__c FROM BMCServiceDesk__Incident__c WHERE Id = :action.BMCServiceDesk__FKIncident__c];
                
                if(action.BMCServiceDesk__actionId__c == 'Email Received') {
                                    if(ticket.Relationship_Name__c == 'Random Customer Name') {
                        ticket.Customer_Reference_Number__c = action.BMCServiceDesk__description__c.substringBetween('##');
                            update Ticket;                
                }
           }    
    }

  }
}

Here are some required linkages between the objects being tested.

Incident History relies on an Incident to exist.  It receives emails and creates an incident history record.  I believe all I need to do in my test class is create an incident and an incident history record linked and verify that my trigger updated with the correct chracters located in between the ## delimiters in my substring.  I am having some issues getting a test class created and i think that I am probably overthinking things...

Here is what I have for my test class - currently getting an error Error: Compile Error: unexpected token: 'static' at line 16 column 5
 
@isTest(seeAllData=false)
Private class SCHParseReceivedEmailTest {

    public static List<Contact> contactsList;
    public static List<BMCServiceDesk__Incident__c> ticketsList;
    public static List<Account> accountsList;
    public static List<BMCServiceDesk__IncidentHistory__c> historyList;
    
    static void init(){
        contactsList = new List<Contact>();
        ticketsList = new List<BMCServiceDesk__Incident__c>();
        accountsList = new List<Account>();
        historyList = new List<BMCServiceDesk__IncidentHistory__c>();
        
    // Test Initiation
    static testMethod void testSCHParsingUpdater() {
    init();
    Test.startTest();
        
    // Create a test account, with test contact, as a requirement to create a new ticket (required fields)
    accountsList.add(new Account(
        Name = 'Random Customer Name',
        Type = 'Customer - Direct',
        Support_Level__c = 'Managed Services'
        ));
            Insert accountsList;
            
    contactsList.add(new Contact(
        LastName = 'SCH Testing',
        Phone = '5555555555',
        Email = 'test@testing.com',
        Account = [Select Id from Account where Name = 'Random Customer Name'].Id
        ));
            Insert contactsList;
    
    // Create a test ticket to be the updated record of the trigger
    ticketsList.add(new BMCServiceDesk__Incident__c(
        BMCServiceDesk__FKContact__c = [Select Id from Contact where LastName = 'SCH Testing'].Id,
        BMCServiceDesk__FKImpact__c = [Select Id from BMCServiceDesk__Impact__c where Name = '1-Enterprise-wide'].Id,   
        BMCServiceDesk__Urgency__c = [Select Id from BMCServiceDesk__Urgency__c where Name = '4 LOW'].Id,
        Customer_Reference_Number__c = 'SCH Testing',
        BMCServiceDesk__FKCategory__c = [Select Id from BMCServiceDesk__Category__c where Name = 'Request'].Id,
        BMCServiceDesk__shortDescription__c = 'Testing for SCH Parsing Updates'
        ));
            Insert ticketsList;
            
    // Create an Incident History record to be parsed by the ticket
    historyList.add(new BMCServiceDesk__IncidentHistory__c(
        BMCServiceDesk__FKIncident__c = [Select Id from BMCServiceDesk__Incident__c where Customer_Reference_Number__c = 'SCH testing'].Id,
        BMCServiceDesk__FKAction__c = [Select Id from BMCServiceDesk__Action__c where Name = 'Email Received'].Id,
        BMCServiceDesk__description__c = 'Email Received-SCH Internal Ticket Number##CHG0763071## Request Type##SCH Firewall Requests##',
        BMCServiceDesk__note__c = 'Email Received-SCH Internal Ticket Number##CHG0763071## Request Type##SCH Firewall Requests## (Ref:IN:01090698)'
        ));
            Insert historyList;
            }
            
    // Verify the trigger completed the customer reference field update
    ticketsList = [
        SELECT Id, Customer_reference_number__c
        FROM BMCServiceDesk__Incident__c
        WHERE Id = :ticketsList[0].Id
        ];
        
    // Verification
    System.asserEquals(ticketsList[0].Customer_reference_number__c, 'CHG0763071');
    
    Test.stopTest();
    }
}

 
Hi All,

I have the following, basic, inbound email handler class:
 
global class ProcessInboundEmailSupport implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

     BMCServiceDesk__Incident__c ticket = new BMCServiceDesk__Incident__c();   
        if([select count() from Account where Account.Support_Email_Service__c = :email.toAddresses] == 0) {

            }
            else {
                 ticket.BMCServiceDesk__FKAccount__c = [select Id from Account where Account.Support_Email_Service__c = :email.toAddresses].Id;
                 ticket.BMCServiceDesk__shortDescription__c = email.subject;
                 ticket.BMCServiceDesk__incidentDescription__c = email.plaintextbody;
                 ticket.BMCServiceDesk__FKContact__c = [select Id from Contact where contact.Email = :email.fromAddress].Id;
                 ticket.Source__c = 'Email';
                 ticket.BMCServiceDesk__FKCategory__c = 'a2kS0000000lg1Q';
                 ticket.Emailed_From__c = email.fromAddress;
                 }
          
    insert ticket;

    System.debug('====> Created ticket '+ticket.Id);
    
            
    BMCServiceDesk__IncidentHistory__c action = new BMCServiceDesk__IncidentHistory__c();
        action.BMCServiceDesk__FKAction__c = 'a0QS0000003wjRR';
        action.BMCServiceDesk__note__c = 'From:' +' '+ email.fromAddress +'\n'+ 'To:' +' '+ email.toAddresses +'\n'+ 'Cc:' +' '+ email.ccAddresses +'\n'+ 'Subject:' +' '+ email.subject +'\n'+ 'Body:' +' '+ email.plaintextbody;
        action.BMCServiceDesk__FKIncident__c = ticket.id;
            insert action;

    if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
      for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
        Attachment attachment = new Attachment();
        
        attachment.ParentId = ticket.Id;
        attachment.Name = email.binaryAttachments[i].filename;
        attachment.Body = email.binaryAttachments[i].body;
        insert attachment;
      }
    }

    return result;

  }

}

The class works just fine for me, however, when I am trying to create a test class, I keep receiving nullpoint exceptions - it's always line 24
 
@isTest
public class TestSupportHandler {
 public static testMethod void TestMyController() {

  // create a new email and envelope object
  Messaging.InboundEmail email = new Messaging.InboundEmail() ;
  Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

  // setup the data for the email
  email.subject = 'Test Email Subject';
  env.fromAddress = 'sbrady@digitalhands.com';

  // add an attachment
  Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfile.txt';
  attachment.mimeTypeSubType = 'text/plain';

  email.binaryAttachments =
    new Messaging.inboundEmail.BinaryAttachment[] { attachment };

  // call the email service class and test it with the data in the testMethod
  ProcessInboundEmailSupport emailProcess = new ProcessInboundEmailSupport();
  emailProcess.handleInboundEmail(email, env);

  // query for the ticket the email service created
  BMCServiceDesk__Incident__c ticket = [select id, Emailed_From__c  from BMCServiceDesk__Incident__c
    where Emailed_From__c = :env.fromAddress];

  System.assertEquals(ticket.Emailed_From__c,'sbrady@digitalhands.com');
 
  // find the attachment
  Attachment a = [select name from attachment where parentId = :ticket.id];

  System.assertEquals(a.name,'textfile.txt');

}
}

I have two questions:
1. Why am I receiving that error when I believe that variable is defined above on the previous line.
2. I am not the best with test classes, so I know that this will not test ALL of my class and I will need to add to it - however would this test class point me in the right direction? Or do I need to change quite a bit?

Any assistance that could be provided would be wonderful, I am still learning a bit about the test classes/requirements as I go.   
Hi All,

On 5/26/2017 I had created an email service within a new sandbox to test an email handler - everything was working just fine on that date. Then on 5/29/2017 I was no longer able to email the sandbox, receiving this error:

dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com (dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com)
Your message couldn't be delivered. The Domain Name System (DNS) reported that the recipient's domain does not exist.
Contact the recipient by some other means (by phone, for example) and ask them to tell their email admin that it appears that their domain isn't properly registered at their domain registrar. Give them the error details shown below. It's likely that the recipient's email admin is the only one who can fix this problem.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Diagnostic information for administrators:
Generating server: BY2PR11MB0613.namprd11.prod.outlook.com
dhtest2@7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com
Remote Server returned '550 5.4.310 DNS domain does not exist [Message=InfoDomainNonexistent] [LastAttemptedServerName=7g5j57uejkh4vt0bibcq1xco2hws8etoi9fuw21zizsshsahg.s-3l1wvmak.cs1.apex.sandbox.salesforce.com] [CO1NAM03FT010.eop-NAM03.prod.protection.outlook.com]'

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Could this be at all related to our internal network? We didn't change antyhing..  Or does this seem like a Salesforce issue? I am surprised that within 3 days it worked and then stopped working.  Anyone have any idea or perhaps has experienced this problem before in their instance?

I reached out to support but was told that email services are a developer issue, not something support can offer assistance with (even though it's a standard functionality).  Last bit of info - no matter what I use for the apex class associated with the email service, i cannot send any emails into the sandbox.  All Email is also enabled within the sandbox.





 
Hi All,

I am in search of some assistance with helping me get a very simple controller into production.  I currently have 31% test coverage but I am running into issues confirming a page reference (and perhaps I may be missing something else to test to get to 75% coverage).  See my controller below:
 
public with sharing class dhrequestsInsertController
{
    public dhrequest__c requests {
        get {
            if(requests == null)
                requests = new dhrequest__c();
        return requests;
        }
        set;
   
    }
      
       
    public dhrequestsInsertController() {
    }
    
    public PageReference SubmitRequest() {
    try {
        insert requests;
        } catch (DMLException e) {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new request. Please contact the Business Intelligence Team.'));
      }
      PageReference detailPage = new PageReference('/' + requests.id);
      return detailPage;
}


    public PageReference CancelRequest() {
        PageReference pr = new PageReference('/apex/dhrequests');
        pr.setRedirect(true);
        return pr;
}
}

Now here is my current test class in progress, sitting at 31% coverage at the moment.  Any tips would be most appreciated! Thank you very much in advance.
 
@isTest
public class dhrequestsInsertControllerTest {

public static testMethod void dhrequestsInsertControllerTest() {


    PageReference pageRef = Page.dhrequestdiscovery;
        Test.setCurrentPage(pageRef);
        
    dhrequestsInsertController controller = new dhrequestsInsertController();
                    
    dhrequest__c r = new dhrequest__c(dh_businesscase__c='test', dh_errormessage__c='error', dh_workaround__c='workaround');
    System.debug('business case before inserting: ' + r.dh_businesscase__c);   
        Insert r;
    
    String nextPage = controller.SubmitRequest().getUrl();
        System.assertEquals('/' + dhrequest__c.id, nextPage);    
    
        
    r = [SELECT dh_businesscase__c, id, dh_errormessage__c, dh_workaround__c FROM dhrequest__c WHERE id =:r.Id];
        System.debug('business case after inserting: ' + r.dh_businesscase__c); 
        System.debug('error after inserting: ' + r.dh_errormessage__c);
        System.debug('workaround after inserting: ' + r.dh_workaround__c);   
         
                      
    System.assertEquals('test', r.dh_businesscase__c);
    System.assertEquals('error', r.dh_errormessage__c);
    System.assertEquals('workaround', r.dh_workaround__c);    
        
        
    String lastPage = controller.CancelRequest().getUrl();
        System.assertEquals('/apex/dhrequests', lastPage);
        
  
    }
}


the SubmitRequest() pageref is giving me fits because I need to confirm that the record that is inserted, it's record Id is contained in the submitrequest redirect (to the detail page of the customer object).  I am getting mismatches there.  I also do not know how to replicate the error message itself, since it's really a catch all.  Any ideas?  Thanks again in advance.
 

Best,
Scott

Hi There,

I am trying to write an APEX Class to be scheduled every year on March 1st and September 1st at 12am that will go out and edit/save all records of a customer object (Personnel_Management__C). The reason for the requirement is that we have semi-annual audit that needs to be performed on our employee information. Nothing needs to be updated, but there is a process/flow behind the scenes that I want to have triggered so that the automated approval processes and other business processes that are included in the process run.  The only way I can see this happening is for an update to be made to each record that would require an audit - scheduled apex.

the customer object in question is Personnel_Management__C - At any given audit, 100+ records could qualify for the select statement for an update (keep in mind, I just want to edit and then save each record, not actually change any values).

The criteria to be met is that within Personnel_Management__C there is a picklist field that is called Employment_Status__C.  This field needs to be "Current Employee" in order for it to qualify for the select statement.

I really appreciate your time and effort to help me get this done - thanks in advance (I am hoping this is quite simple and will serve as a great learning experience for me).