• ChrisSargent
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
Hello,

I'm writing a simple Apex class that will change the field of a contact when an email is sent to a BCC salesforce email services address. I've written the class in my Sandbox and it all seems to be working fine so I now need to test it to I can deploy it to my production environment. I've written a test as far as I can so far and I'm getting no errors, with 50% code coverage.

I'm not quite sure what else I need to test to be able to get to 100% code coverage; any help would therefore be much appreciated.

Here's my Class:

global class UpdateToutAppStage implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
 
    // Create an InboundEmailResult object for returning the result of the Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    String emailSubject = email.Subject;
    String [] emailToList = email.toAddresses;
    String newStage = null;
    String toEmail = null;
     
    // Run a for loop through the "email to" list, in case of sending to multiple people.
    for(Integer i = 0; i < emailToList.size(); i++){
        toEmail = emailToList[i];


        // Try to look up any contacts based on the email to address
        // If there is more than one contact with the same email address, an exception will be thrown and the catch statement will be called.
    
        try {
          Contact vCon = [SELECT Id, Name, Email
            FROM Contact
            WHERE Email = :toEmail
            LIMIT 1];
          
         // Check the Email Subject and Adjust the newStage variable accordingly.
    
         if (emailSubject == 'Congratulations on your recent funding' || emailSubject == 'Hiring awesome people for amazing companies'){
                 newStage = 'Stage 1';
             }
         else if (emailSubject == 'Re: Congratulations on your recent funding' || emailSubject == 'Re: Hiring awesome people for amazing companies'){
                 newStage = 'Stage 2';
             }    
         else if (emailSubject == 'Trying to connect'){
                 newStage = 'Stage 3';
             }
         else if (emailSubject.contains('take this thing offline?')){
                 newStage = 'Stage 4';
             }
         else if (emailSubject.contains('Am I not getting the hint?')){
                 newStage = 'Completed';
             }
         else {
                 newStage = 'Undefined';
              }
         // Set the field to be equal to the variable string
         vCon.Marketing_Campaign__c = newStage;
         
         // Update the Contact record
         update vCon;
         
         // Writes a note to the the debugging log
         System.debug('ToutApp Stage Field Updated To: ' + newStage );   
         }
         
         // If an exception occurs when the query accesses the contact record, a QueryException is called. The exception is written to the Apex debug log.
         catch (QueryException e) {
                System.debug('ToutApp Stage Failed: ' + e);
            }
 
     } // End the For loop
   
     // Set the result to true. No need to send an email back to the user with an error message
     result.success = true;
   
     // Return the result for the Apex Email Service
     return result;
  }
}

And my test class:

@isTest
private class TestUpdateToutAppStage {
    static testMethod void TestUpdateToutApp() {
        // 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 = 'Congratulations on your recent funding';
        String[] toAddresses = new String[] {'me@email1.com','you@email2.com'};
        email.toAddresses = toAddresses;
        
        // call the ToutApp class and test it with the data in the testMethod
        UpdateToutAppStage testInbound = new UpdateToutAppStage ();
        testInbound.handleInboundEmail(email, env);
        }
}

Thanks in advance!

Chris
Hello,

We have a New Candidate wizard that was built for us in Visual Force / Apex. I would like to slightly modify it so that one section isn't displayed until the user ticks a check box (and should disappear if they unselect it again).

Here is a snippet of the code we currently have
           
            <apex:pageBlockSection columns="1" rendered="{!wizardState == 6 || showAll == true}" title="Opportunity Information:">
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Did you speak to this candidate about a live opportunity?</apex:outputLabel>
                    <apex:inputCheckbox value="{!oppAdded}"/>
                </apex:pageBlockSectionItem>
               
                <apex:inputField required="false" value="{!ica.Opportunity__c}" /> 
                <apex:repeat value="{!$ObjectType.IdentifiedCandidateAssociation__c.FieldSets.Candidate_Fields}" var="f"> 
                    <apex:inputfield value="{!ica[f]}"/>
                </apex:repeat>  
                                         
            </apex:pageBlockSection>

I would like it to only display the field from the IdentifiedCandidateAssociation, if the checkbox in the first item is ticked. Is this possible please and can anyone give me some pointers?

I did find this: http://stackoverflow.com/questions/8578748/display-a-text-field-after-a-checkbox-is-checked-in-visualforce but I couldn't use the Disable attribute with an inputField.

Thanks very much!

Chris

Hello,

 

I haven't used Triggers before and before I go down the path of learning them in depth I'd like to know if they could actually achieve what I'm looking to to. Essentially, in several areas of Salesforce we have records that are linked to other records via junction objects. I would like to make the creation of these junction objects required before the 'owing object' is saved.

 

For example, I notice in standard salesforce, you have the related list on cases called case comments. If it's possible to write a trigger that would require a user to add a case comment to any case they create (otherwise the case will not save / will be deleted) then probably I can achieve what I want....

 

Any help / advice would be much appreciated....

 

Thanks!

 

Chris

Hello,

I'm writing a simple Apex class that will change the field of a contact when an email is sent to a BCC salesforce email services address. I've written the class in my Sandbox and it all seems to be working fine so I now need to test it to I can deploy it to my production environment. I've written a test as far as I can so far and I'm getting no errors, with 50% code coverage.

I'm not quite sure what else I need to test to be able to get to 100% code coverage; any help would therefore be much appreciated.

Here's my Class:

global class UpdateToutAppStage implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
 
    // Create an InboundEmailResult object for returning the result of the Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    String emailSubject = email.Subject;
    String [] emailToList = email.toAddresses;
    String newStage = null;
    String toEmail = null;
     
    // Run a for loop through the "email to" list, in case of sending to multiple people.
    for(Integer i = 0; i < emailToList.size(); i++){
        toEmail = emailToList[i];


        // Try to look up any contacts based on the email to address
        // If there is more than one contact with the same email address, an exception will be thrown and the catch statement will be called.
    
        try {
          Contact vCon = [SELECT Id, Name, Email
            FROM Contact
            WHERE Email = :toEmail
            LIMIT 1];
          
         // Check the Email Subject and Adjust the newStage variable accordingly.
    
         if (emailSubject == 'Congratulations on your recent funding' || emailSubject == 'Hiring awesome people for amazing companies'){
                 newStage = 'Stage 1';
             }
         else if (emailSubject == 'Re: Congratulations on your recent funding' || emailSubject == 'Re: Hiring awesome people for amazing companies'){
                 newStage = 'Stage 2';
             }    
         else if (emailSubject == 'Trying to connect'){
                 newStage = 'Stage 3';
             }
         else if (emailSubject.contains('take this thing offline?')){
                 newStage = 'Stage 4';
             }
         else if (emailSubject.contains('Am I not getting the hint?')){
                 newStage = 'Completed';
             }
         else {
                 newStage = 'Undefined';
              }
         // Set the field to be equal to the variable string
         vCon.Marketing_Campaign__c = newStage;
         
         // Update the Contact record
         update vCon;
         
         // Writes a note to the the debugging log
         System.debug('ToutApp Stage Field Updated To: ' + newStage );   
         }
         
         // If an exception occurs when the query accesses the contact record, a QueryException is called. The exception is written to the Apex debug log.
         catch (QueryException e) {
                System.debug('ToutApp Stage Failed: ' + e);
            }
 
     } // End the For loop
   
     // Set the result to true. No need to send an email back to the user with an error message
     result.success = true;
   
     // Return the result for the Apex Email Service
     return result;
  }
}

And my test class:

@isTest
private class TestUpdateToutAppStage {
    static testMethod void TestUpdateToutApp() {
        // 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 = 'Congratulations on your recent funding';
        String[] toAddresses = new String[] {'me@email1.com','you@email2.com'};
        email.toAddresses = toAddresses;
        
        // call the ToutApp class and test it with the data in the testMethod
        UpdateToutAppStage testInbound = new UpdateToutAppStage ();
        testInbound.handleInboundEmail(email, env);
        }
}

Thanks in advance!

Chris

Hello,

 

I haven't used Triggers before and before I go down the path of learning them in depth I'd like to know if they could actually achieve what I'm looking to to. Essentially, in several areas of Salesforce we have records that are linked to other records via junction objects. I would like to make the creation of these junction objects required before the 'owing object' is saved.

 

For example, I notice in standard salesforce, you have the related list on cases called case comments. If it's possible to write a trigger that would require a user to add a case comment to any case they create (otherwise the case will not save / will be deleted) then probably I can achieve what I want....

 

Any help / advice would be much appreciated....

 

Thanks!

 

Chris

We have a custom application that we've built in a Developer account, and we'd like to deploy it to our production Salesforce instance. We recently tried to do this using the Force.com IDE's deployment tool, but it failed, because a unit test for a different plugin (Inline Account Hierarchy) failed, bringing our overall code coverage down to 68%.

Specifically, the message returned when the assertion fails is: "Pre deploy test failed, This may be because of custom validation rules in your Org. You can check ignore apex errors or temporarily deactivate your validation rules for Accounts and try again." Again, this is returned by Inline Account Hierarchy, NOT our application.

We're unaware of any custom validation rules, but where can we look to confirm that we do or do not have any?

Please advise as to what the best course of action is here. We're heavily reliant on the Inline Account Hierarchy functionality, but we also need our own app (which has 98% coverage) to be deployed as soon as possible.

  • January 03, 2013
  • Like
  • 0

I've recently encountered the phenomenon in which new/edited contact workflow rules are triggered when moving a contact record from one account to another.  I'm surprised I have not noticed this before.    I was updating contacts via the Web API, changing their account affiliation, and to my surprise some e-mails were sent out because a workflow that triggers on "When a record is created, or when a record is edited and did not previously meet the rule criteria" for contacts" fired off.  I also saw that just changing an contact's account within Salesforce (using the web UI) has the same effect.

 

I assume this means that "new contact" in Salesforce means "contact is new to an account"?    

 

Is this true?  Is there a way to keep such workflows from firing?   I can assure you that the rule criteria has nothing to do with the contact's account.  Such a change should not be firing the workflow.

 

thanks,

 

Jason Gabler