• Gabe Sanchez 7
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 7
    Replies
Hello, 
Had some help from a community user but cant figure out how to get this to work. I am brand new to Apex. I am trying to parse an email message and insert it into a field in salesforce. II have created the class and here is the code : 

 
public class InvocableMethods {
02
     
03
    @InvocableMethod( label='Ger Ref Id' description='' category='Case' )
04
    public static void getRefId( List<EmailMessage> emailMsgList ){
05
        List<Case> casesToUpdate = new List<Case>();
06
        for( EmailMessage em : emailMsgList ){
07
            if( em.TextBody != null ){
08
                Matcher m = Pattern.compile('ref:+.......[0-9]').matcher(em.TextBody);
09
                if( m.find() ){
10
                    casesToUpdate.add( new Case( Id = em.RelatedToId, ServiceNow_Ref_Code__c = m.group() ) );
11
                }
12
            }
13
        }
14
        update casesToUpdate;
15
    }
16
     
17
}


I am trying to get "ref:123456789" from the body of the email and insert it into "ServiceNow_Ref_Code__c", 

I have set up process builder and it looks like this :

User-added imageUser-added imageAny ideas on what I am doing wrong here?

Thanks!

Gabe

 

I am trying to capture a portion of the body of an email from a certain client in salesforce. Basically, the body will also have "ref:20392039". I want to capture that and drop it into our field in SF called Service Now Ref Code. Any ideas on how to do this?
I am trying to capture a portion of the body of an email from a certain client in salesforce. Basically, the body will also have "ref:20392039". I want to capture that and drop it into our field in SF called Service Now Ref Code. Any ideas on how to do this?
Hello, 
I am working on inbound email service to update a field in Salesforce. 
When I receive an email from a specific email address, I need to look for the email content to see if it contains words "FULL OUT". If it does, I need to find the serial number on the email content to match a record Container (API: Container__c) in Salesforce. Then update Status field (picklist; API: Status__c) on that Container record. How to write the Apex code to look for the words? Please see the example email below: 
From: xxx@gmail.com

Service FULL OUT was performed for shipments listed below
ABCDEF123: (this is the serial number and a container name in Salesforce) I need to find this serial number in email and see if a container record is created in Salesforce. 
Size: 12
Destination: NY
Delivery Date: 01/18/2018
 
So after discovering that I needed to develop apex classes/triggers to mark my "completed" milestone as complete when a case is closed I've noticed an issue.  Basically if a previously closed case is reopened the "completed" milestone needs to be marked as active again as the SLA is technically live again. 

Can't think of a way to code a trigger to do this.  So basically it needs to clear the completed date/time field when cased close was previously true but now isn't.

Here is my apex class:
 
public class milestoneUtils {
    
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
      
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
  }

Here is the trigger that marks the "closed" milestone as complete once case closed is true:
 
trigger completeResolutionTimeMilestone on Case (after update) {

    // Cannot be a portal user
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now();
            List<Id> updateCases = new List<Id>();
            for (Case c : Trigger.new){
                if (((c.isClosed == true))&&((c.SlaStartDate <= completionDate)&&(c.SlaExitDate == null)))
            updateCases.add(c.Id);
        }
    if (updateCases.isEmpty() == false)
        milestoneUtils.completeMilestone(updateCases, 'Closed Milestone', completionDate);
    }
}

Any thoughts on the best way to achieve this?
 
  • June 15, 2015
  • Like
  • 0