I am trying to set a boolean to true upon insert based on first this logic:
if((pr.recordtypeid == '012g0000000D63fAAC' || pr.recordtypeid == '012g0000000D63iAAC' || pr.recordtypeid == '012g0000000D63gAAC' || pr.recordtypeid == '012g0000000D63kAAC' ||
pr.recordtypeid == '012g0000000D63jAAC' || pr.recordtypeid == '012g0000000D63TAAS' || pr.recordtypeid == '012g0000000D63RAAS' || pr.recordtypeid == '012g0000000D63UAAS')
&& pr.route_code__c == 'H - HCFA Print Image (HCFA to NSF)' && pr.Transaction_Format__c== 'S - NSF 3.01' )
and that a record of the same account that is of Emdeon One - Client, '012g0000000D63W' that has print image__c = true.
I am not sure how compose this logic but here is what I have and am getting
AfterInsert caused by: System.FinalException: Record is read-only: Trigger.eOneProdConfigUpdatePrintImage: line 58, column 1
code
trigger eOneProdConfigUpdatePrintImage on Product_Configuration__c (after insert) {
/*RecTypes
"012g0000000D63eAAC","275"
"012g0000000D63fAAC","837"
"012g0000000D63gAAC","837D"
"012g0000000D63hAAC","837DW"
"012g0000000D63iAAC","837I"
"012g0000000D63jAAC","837IW"
"012g0000000D63kAAC","837W"
"012g0000000D63RAAS","CSI"
"012g0000000D63SAAS","EDGE"
"012g0000000D63TAAS","ELG"
"012g0000000D63VAAS","Emdeon One - Channel Partner"
"012g0000000D63WAAS","Emdeon One - Client"
"012g0000000D63XAAS","Emdeon One - Data"
"012g0000000D63YAAS","Emdeon One - Fiscal Intermediary"
"012g0000000D63ZAAS","Emdeon One - Payer"
"012g0000000D63UAAS","ERA"
"012g0000000D63aAAC","Payment"
"012g0000000D63bAAC","Portal Services"
"012g0000000D63cAAC","RFI"
"012g0000000D63dAAC","RFR"*/
set<id> prid = new set<id>();
set<id> acctids = new set<id>();
Map<String, Integer> configmap = new Map<String, Integer>();
List<product_configuration__c>pr2upt = new list<product_configuration__c>();
Integer cnt;
Id acctid;
List<Product_Configuration__c> prodlist = [Select Id, Route_Code__c, ES_Format__c, Account__c from product_configuration__c where recordtypeid = '012g0000000D63W'];
For(product_configuration__c pr: trigger.new) {
if((pr.recordtypeid == '012g0000000D63fAAC' || pr.recordtypeid == '012g0000000D63iAAC' || pr.recordtypeid == '012g0000000D63gAAC' || pr.recordtypeid == '012g0000000D63kAAC' ||
pr.recordtypeid == '012g0000000D63jAAC' || pr.recordtypeid == '012g0000000D63TAAS' || pr.recordtypeid == '012g0000000D63RAAS' || pr.recordtypeid == '012g0000000D63UAAS')
&& pr.route_code__c == 'H - HCFA Print Image (HCFA to NSF)' && pr.Transaction_Format__c== 'S - NSF 3.01' ) {
prid.add(pr.Id);
acctids.add(pr.Account__c);
pr2upt.add(pr);
AggregateResult[] groupedResults = [Select Account__c, count(Name) From Product_Configuration__c where Account__c in : acctids Group by Account__c];
For(AggregateResult ar : groupedresults) {
cnt = (Integer) ar.get('expr0');
acctid = (Id) ar.get('Account__c');
configmap.put(acctid, cnt);
For(Product_Configuration__c emd1 : prodlist) {
if(emd1.Print_Image__c = true && (configmap.containskey(acctid)) ) {
pr.Print_Image__c = true;
}
}
}
}
}
update pr2upt;
}