Apex Send Mail の注意点

例:

Messaging.sendEmail(emails, false);

メール送信すると、送信失敗しました、 エラー:Messaging.SendEmailResult[getErrors=(Messaging.SendEmailError[getTargetObjectId=null;]);isSuccess=false;]

Debugするため、 Messaging.sendEmail(emails, true);
に変更して、 原因は、コードに setTargetObjectId methodを使いましたので
エラーが発生しました
 setTargetObjectIdは Contact/Lead/User だけ使えます、使うと、該当標準メール項目利用して、送信可能

説明:
Required if using a template, optional otherwise. The ID of the contact, lead, or user to which the email will be sent. The ID you specify sets the context and ensures that merge fields in the template contain the correct data

Salesforce String ReplaceAll

String a = ‘文字32十は3十52年, 1十2際十5文字列は十桁です’;

String b = a.replaceAll(‘([0-9])(十)([0-9])’, ‘$1$3’);
String b1 = b.replaceAll(‘([0-9])(十)’, ‘$10’);
String c = b1.replaceAll(‘(十)([0-9])’, ‘1$2’);
String d = c.replaceAll(‘十’,’10’);
System.debug(d);

 

Result:
———————————————
文字320は352年, 12際15文字列は10桁です

Get Record Type By De

//To get the RecordTypeInfo of ApprovedOutBoundMail__c
public static Schema.RecordTypeInfo getRecTypeInfo( String strRecTypeName ){

Schema.DescribeSObjectResult DescPack = Schema.SObjectType.ApprovedOutBoundMail__c;
Map<String,Schema.RecordTypeInfo> appRcName= DescPack.getRecordTypeInfosByName();
Schema.RecordTypeInfo rcType= appRcName.get(strRecTypeName);
return rcType;

}

Salesforce 配列初期化 簡略書き方

http://blog.jeffdouglas.com/2011/01/06/fun-with-salesforce-collections/

省略初期化方法
set -> list :
Set setStrings = new Set{‘hello’,’world’};
List listStrings = new List(setStrings);

// create a new set with 3 elements
Set s = new Set{‘Jon’, ‘Quinton’, ‘Reid’};
// adds an element IF not already present
s.add(‘Sandeep’);
// adds an element IF not already present
s.add(‘Sandeep’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// removes the element if present
s.remove(‘Reid’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// returns true if the set contains the specified element
System.debug(‘=== set contains element Jon: ‘ + s.contains(‘Jon’));
// output all elements in the set
for (String str : s)
// outputs an element
System.debug(‘=== element : ‘ + str);
// makes a duplicate of the set
Set s1 = s.clone();
// displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// removes all elements
s1.clear();
// returns true if the set has zero elements
System.debug(‘=== is the s1 set empty? ‘ + s1.isEmpty());

List s = new List{‘Jon’, ‘Quinton’, ‘Reid’};
// adds an element
s.add(‘Sandeep’);
// adds an element
s.add(‘Sandeep’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// displays the first element
System.debug(‘=== first element: ‘ + s.get(0));
// removes the first element
s.remove(0);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// makes a duplicate of the set
List s1 = s.clone();
// displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// replace the last instance of ‘Sandeep’ with ‘Pat’
s1.set(3,’Pat’); // displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// sorts the items in ascending (primitave only)
s1.sort();
// displays the contents of the set
System.debug(‘=== sorted contents of s1: ‘ + s1);
// removes all elements
s.clear();
// returns true if the set has zero elements
System.debug(‘=== is the list empty? ‘ + s.isEmpty());

Map m = new Map{5 => ‘Jon’, 6 => ‘Quinton’, 1 => ‘Reid’};
// displays all keys
System.debug(‘=== all keys in the map: ‘ + m.keySet());
// displays all values
System.debug(‘=== all values in the map (as a List): ‘ + m.values());
// does the key exist?
System.debug(‘=== does key 6 exist?: ‘ + m.containsKey(6));
// fetches the value for the key
System.debug(‘=== value for key 6: ‘ + m.get(6));
// adds a new key/value pair
m.put(3,’Dave’);
// returns the number of elements
System.debug(‘=== size after adding Dave: ‘ + m.size());
// removes an element
m.remove(5);
System.debug(‘=== size after removing Jon: ‘ + m.size());
// clones the map
Map m1 = m.clone();
System.debug(‘=== cloned m1: ‘ + m1);
// removes all elements
m.clear();
// returns true if zero elements
System.debug(‘=== is m empty? ‘ + m.isEmpty());