You need to sign in to do that
Don't have an account?
Mayur Naidu 17
Hello! I am trying to iterate on new Trigger map to compare a value of an element indexed 1 with element indexed at 0. I am not able to declare index in Apex. Below is my code. Any help would be appreciated. Thank you!
if (clmMap.size() > 0){
for(Clm_Presentation_vod__c clm : clmMap.values()){
for(Integer i = 1; i < clmMap.size(); i++){
Integer version1 = Integer.valueOf(clmMap.get(clm[i].Version_vod__c));
Integer version2 = Integer.valueOf(clmMap.get(clm[i-1].Version_vod__c));
String docId1 = clmMap.get(clm[i].Vault_Doc_Id_vod__c);
String docId2 = clmMap.get(clm[i-1].Vault_Doc_Id_vod__c);
if (docId1 == docId2){
if (version1 > Version2){
Trigger.newMap.get(clm[i].Show_Offline_abv__c = True);
Trigger.newMap.get(clm[i-1].Show_Offline_abv__c = false);
}else {
Trigger.newMap.get(clm[i].Show_Offline_abv__c) = false;
Trigger.newMap.get(clm[i-1].Show_Offline_abv__c = True);
}
}
}
}
}
for(Clm_Presentation_vod__c clm : clmMap.values()){
for(Integer i = 1; i < clmMap.size(); i++){
Integer version1 = Integer.valueOf(clmMap.get(clm[i].Version_vod__c));
Integer version2 = Integer.valueOf(clmMap.get(clm[i-1].Version_vod__c));
String docId1 = clmMap.get(clm[i].Vault_Doc_Id_vod__c);
String docId2 = clmMap.get(clm[i-1].Vault_Doc_Id_vod__c);
if (docId1 == docId2){
if (version1 > Version2){
Trigger.newMap.get(clm[i].Show_Offline_abv__c = True);
Trigger.newMap.get(clm[i-1].Show_Offline_abv__c = false);
}else {
Trigger.newMap.get(clm[i].Show_Offline_abv__c) = false;
Trigger.newMap.get(clm[i-1].Show_Offline_abv__c = True);
}
}
}
}
}
Hi Mayur,
Map is combination of (Key and Value). Here indexing is maintained by KEYS. Therefore make sure your 'clm[i].Version_vod__c' should be the the KEY that your map is containing. I'm putting example below.
Map<Integer,String> newMap = new Map<Integer,String>();
newMap.put(0,'aaaaa'); // Here '0' is the Key and 'aaaaa' is the value.
newMap.put(1,'bbbbb');
newMap.put(2,'ccccc');
newMap.put(3,'ddddd');
newMap.put(4,'eeeee');
for(integer i=0 ;i<newMap.size(); i++){
System.debug('--->'+newMap.get(i)); // newMap.get(0) ---> aaaaa
}
Hope this helps!
Thanks,
Sucharita
newMap.put(4,'aaaaa');
newMap.put(908,'bbbbb');
newMap.put(221,'ccccc');
newMap.put(332,'ddddd');
newMap.put(423,'eeeee');
How will we be able to iterate through this map and compare values with previous element?