public without sharing class QISTrigger {
|
// QISのId
|
public static Set<Id> QIS_Ids = new Set<Id>();
|
|
//
|
public static void setPhotoImgText(List<QIS_Report__c> newList, List<QIS_Report__c> oldList, Map<Id, QIS_Report__c> newMap, Map<Id, QIS_Report__c> oldMap) {
|
for (QIS_Report__c qr : newList) {
|
// 二重実行禁止
|
if (QIS_Ids.contains(qr.Id)) continue;
|
// Photo1
|
if (Trigger.isInsert && String.isBlank(qr.Photo_1__c) == false
|
|| (Trigger.isUpdate && ((QIS_Report__c) oldMap.get(qr.Id)).Photo_1__c != qr.Photo_1__c)
|
|| (Trigger.isUpdate && String.isBlank(qr.Photo_1__c) == false && String.isBlank(qr.Photo_1_Text__c))
|
) {
|
String phtTxt = '';
|
if (String.isBlank(qr.Photo_1__c) == false) {
|
Integer pStt = qr.Photo_1__c.indexOf('<img');
|
if (pStt >= 0) {
|
pStt = qr.Photo_1__c.indexOf('src="');
|
if (pStt >= 0) {
|
Integer pEnd = qr.Photo_1__c.indexOf('"', pStt + 5);
|
if (pEnd >= 0) {
|
phtTxt = qr.Photo_1__c.substring(pStt + 5, pEnd);
|
phtTxt = phtTxt.unescapeHtml4();
|
}
|
}
|
}
|
}
|
qr.Photo_1_Text__c = phtTxt;
|
QIS_Ids.add(qr.Id);
|
}
|
// Photo2
|
if (Trigger.isInsert && String.isBlank(qr.Photo_2__c) == false
|
|| (Trigger.isUpdate && ((QIS_Report__c) oldMap.get(qr.Id)).Photo_2__c != qr.Photo_2__c)
|
|| (Trigger.isUpdate && String.isBlank(qr.Photo_2__c) == false && String.isBlank(qr.Photo_2_Text__c))
|
) {
|
String phtTxt = '';
|
if (String.isBlank(qr.Photo_2__c) == false) {
|
Integer pStt = qr.Photo_2__c.indexOf('<img');
|
if (pStt >= 0) {
|
pStt = qr.Photo_2__c.indexOf('src="');
|
if (pStt >= 0) {
|
Integer pEnd = qr.Photo_2__c.indexOf('"', pStt + 5);
|
if (pEnd >= 0) {
|
phtTxt = qr.Photo_2__c.substring(pStt + 5, pEnd);
|
phtTxt = phtTxt.unescapeHtml4();
|
}
|
}
|
}
|
}
|
qr.Photo_2_Text__c = phtTxt;
|
QIS_Ids.add(qr.Id);
|
}
|
// Photo3
|
if (Trigger.isInsert && String.isBlank(qr.Photo_3__c) == false
|
|| (Trigger.isUpdate && ((QIS_Report__c) oldMap.get(qr.Id)).Photo_3__c != qr.Photo_3__c)
|
|| (Trigger.isUpdate && String.isBlank(qr.Photo_3__c) == false && String.isBlank(qr.Photo_3_Text__c))
|
) {
|
String phtTxt = '';
|
if (String.isBlank(qr.Photo_3__c) == false) {
|
Integer pStt = qr.Photo_3__c.indexOf('<img');
|
if (pStt >= 0) {
|
pStt = qr.Photo_3__c.indexOf('src="');
|
if (pStt >= 0) {
|
Integer pEnd = qr.Photo_3__c.indexOf('"', pStt + 5);
|
if (pEnd >= 0) {
|
phtTxt = qr.Photo_3__c.substring(pStt + 5, pEnd);
|
phtTxt = phtTxt.unescapeHtml4();
|
}
|
}
|
}
|
}
|
qr.Photo_3_Text__c = phtTxt;
|
QIS_Ids.add(qr.Id);
|
}
|
// Photo4
|
if (Trigger.isInsert && String.isBlank(qr.Photo_4__c) == false
|
|| (Trigger.isUpdate && ((QIS_Report__c) oldMap.get(qr.Id)).Photo_4__c != qr.Photo_4__c)
|
|| (Trigger.isUpdate && String.isBlank(qr.Photo_4__c) == false && String.isBlank(qr.Photo_4_Text__c))
|
) {
|
String phtTxt = '';
|
if (String.isBlank(qr.Photo_4__c) == false) {
|
Integer pStt = qr.Photo_4__c.indexOf('<img');
|
if (pStt >= 0) {
|
pStt = qr.Photo_4__c.indexOf('src="');
|
if (pStt >= 0) {
|
Integer pEnd = qr.Photo_4__c.indexOf('"', pStt + 5);
|
if (pEnd >= 0) {
|
phtTxt = qr.Photo_4__c.substring(pStt + 5, pEnd);
|
phtTxt = phtTxt.unescapeHtml4();
|
}
|
}
|
}
|
}
|
qr.Photo_4_Text__c = phtTxt;
|
QIS_Ids.add(qr.Id);
|
}
|
}
|
}
|
}
|