2011-07-26 7 views
1

私はIMAP4受信トレイにクライアントからの電子メールをポーリングし、それに基づいてSalesforceで新しいケースを作成するWindowsサービスを作成しています。Salesforce API:電子メール参照コード( "[Ref:...:Ref]")からケースを特定する方法?

メールには、件名にCase参照コードが含まれることがあります。例: "[ref:00FFwxyz.500FFJJS5:ref]"私は新しい電子メールを作成するのではなく、コードで特定された既存のケースにそのような電子メールを割り当てたいと思います。

私の質問は:refコードから一意のCase識別子を抽出するための決定的な式はありますか?私は逆を行ういくつかの数式を見てきましたが、それらはすべておとぎ話のようです:Blog post on KnowThyCloud.comForce.com Discussion Board thread

答えて

2

十分な解決策が見つかりました。私はthe post on KnowThyCloud.comの推測に間違っていました。適切なコンテキストでは正常に動作します。

私の解決方法は、「式(テキスト)」タイプのケースレコードに新しいカスタムフィールドを作成することです。フィールドの値は、ブログ記事で述べた式である:

TRIM(" [ ref:" + LEFT($Organization.Id, 4) + RIGHT($Organization.Id, 4) +"."+ LEFT(Id, 4) + SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Id, RIGHT(Id, 4), ""), LEFT(Id, 4), ""), "0", "") + RIGHT(Id, 4) + ":ref ] ") 

今、各ケースのレコードのカスタムフィールドの値は、メールの参照IDと同じであると私は単純にSalesforceのAPIでそれを照会することができます。

1

私はurigのソリューションを実装しており、うまく機能します。

ここには、このフィールドがないケースを特定するApexコードソリューションがあります。

String emailSubject = 'FW: Re: RE: order 36000862A Case: 00028936 [ ref:00D7JFzw.5007Ju10k:ref ]'; 
String caseNumber = null; 
/* 
Extract the text after ref: and before the period. Could use this to locate the organization. 
In the text after the period and before the :ref split into a 4 digit number and remaining number. 
Insert 0's to get ref id. 
*/ 
String patternString = '.*ref:(.{8}).(.{4})(.+):ref.*'; 
Pattern thePattern = Pattern.compile(patternString); 
Matcher matcher = thePattern.matcher(emailSubject); 

if (matcher.matches()) { 
    String caseId = matcher.group(2) + '000000' + matcher.group(3); 
    Case[] matchingCases = [Select CaseNumber from Case where Id = :caseId]; 
    if(matchingCases.size() == 1) { 
     Case theCase = matchingCases[0]; 
     caseNumber = theCase.CaseNumber; 
    }  
} 
0

Iはunderrscores(例えば_00DC0PxQg._500C0KoOZS)を含有する新たな基準文字列をサポートするために、上記月のコードスニペットを変更しました。

String patternString = '.*ref:(.{11}).(.{5})(.+):ref.*'; 
Pattern thePattern = Pattern.compile(patternString); 
Matcher matcher = thePattern.matcher(emailSubject); 

if (matcher.matches()) { 
    String caseId = matcher.group(2) + '00000' + matcher.group(3); 
    system.debug('### '+caseId); 
    Case[] matchingCases = [Select CaseNumber from Case where Id = :caseId]; 
    if(matchingCases.size() == 1) { 
     Case theCase = matchingCases[0]; 
     caseNumber = theCase.CaseNumber; 
    }  
} 
関連する問題