在salesforce Apex中,我有一个以下字符串并且面临着如何一次迭代两张地图的问题?有人可以指导我......我们怎么做到这一点?
String values = 'Auth Group:true,HR Group:false';
Auth Group:true,HR Group:false
我有两张地图
// Map of GroupId and GroupName
Map<Id, String> mapGrpIdAndName = new Map<Id, String>();
mapGrpIdAndName.put('Auth Group','111');
mapGrpIdAndName.put('HR Group','222');
// Map of GroupName and Indicator
Map<String, String> mapGrpNameAndIndicator = new Map<String, String>();
mapGrpNameAndIndicator.put('Auth Group','false');
mapGrpNameAndIndicator.put('HR Group','true');
Assume I am in for loop of case already
for(payment_2__c mysi2 : newSI2){
Boolean f_indicator = // True or False ==> This value is dynamic........
if(caseMap.get(mysi2.Case__c).RecordType.DeveloperName != 'ELC_DraftCase'){
if(caseMap.get(mysi2.Case__c).OwnerId != mysi2.OwnerId){
if(caseMap.get(mysi2.Case__c).RecordType.DeveloperName == 'AAA_HR'){
for(Id grpId : mapGrpIdAndName.keySet()){
//// HERE I need to check dynamicallt if value of
/// if f_indicator == false and Auth Group == false, then only give apex sharing
// How to iterate over two map at a time ???????
////
ELC_Service_Information_2__Share gsiShare2 = new ELC_Service_Information_2__Share();
gsiShare2.ParentId = mysi2.Id;
gsiShare2.RowCause = 'Manual';
gsiShare2.AccessLevel = 'Edit';
gsiShare2.UserOrGroupId = grpId;
si_2ShareList.add(gsiShare2);
}
}
}
}
}
答案 0 :(得分:0)
这会编译吗?您的第一个Map(mapGrpIdAndName)被实例化以存储Id和String;但是,你要在其中存储两个字符串。
此外,如果您已经遍历案例,则不需要从案例地图中检索值。
很难理解为什么要创建地图只存储两个真/假值。我想你不会遗漏真实的代码,所以我们不会使用它。
如果不循环遍历第二张地图,就可以这样做:
for(Id grpId : mapGrpIdAndName.keySet()){
if(f_indicator == false && mapGrpNameAndIndicator.get(mapGrpIdAndName.get(grpId)) == 'false'){
//do whatever
}
}
由于Group是一个sObject,你可以使用类似的东西:
Map<Id, Group> mpGroups = new Map<Id, Group>([SELECT Id, Name FROM Group]);
for(Id grpId : mpGroups.keySet()){
if(f_indicator == false && mpGroups.get(grpId).Indicator__c == 'false'){
//do whatever
}
}
或者:
Map<Id, Group> mpGroups = new Map<Id, Group>([SELECT Id, Name FROM Group]);
for(Group grp : mpGroups.values()){
if(f_indicator == false && grp.Indicator__c == 'false'){
//do whatever
}
}