You need to sign in to do that
Don't have an account?
F Smoak
custom label translation not working
I have created a batch class that creates records on custom object Alert. Now I want the alert name to be available for english and french user so I have created custom label for same, but when I login with french user I cannot see french translation but only english text, please help!
global class CMS_Batch_Alert_Submitted_Call implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
List<Pfizer_Country_Code_Setting__mdt> metadataList = [Select Label from Pfizer_Country_Code_Setting__mdt];
List<String> countrycodeList = new List<String>();
for(Pfizer_Country_Code_Setting__mdt mdt:metadataList){
countrycodeList.add(mdt.Label);
}
String query = 'SELECT id,CMS_Submitted_DateTime__c,Account_vod__c,Account_vod__r.name,ownerid,owner.name,Detailed_Products_vod__c FROM Call2_vod__c where Status_vod__c = \'Submitted_vod\' AND CMS_Submitted_DateTime__c = LAST_N_DAYS:7 and Account_vod__c !=null and CMS_Country_Code__c in : countrycodeList order by CMS_Submitted_DateTime__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject>scope) {
String submittedCallHeader = System.Label.CMS_Submittted_Calls_in_Last_7_Days_Alert_Header;
system.debug('submittedCallHeader>>'+submittedCallHeader);
List<Call2_vod__c> callList = (List<Call2_vod__c>) scope;
system.debug('call list>>>>'+calllist);
List<Alert_vod__c> alertsubmittedcalllist = new List<Alert_vod__c>();
Map<Id,Call2_vod__c> callmap = new Map<Id,Call2_vod__c>();
for(Call2_vod__c c:calllist){
if(!callmap.containsKey(c.account_vod__c)){
callmap.put(c.Account_vod__c,c);
}
else{
Call2_vod__c cc = callmap.get(c.account_vod__c);
if(cc.CMS_Submitted_DateTime__c < c.CMS_Submitted_DateTime__c) {
callmap.remove(c.account_vod__c);
}
callmap.put(c.account_vod__c,c);
}}
system.debug('callmap>>>'+callmap);
Set<String> terrname = new set<String>();
List<Cycle_Plan_Target_vod__c> cptlist = [SELECT Cycle_Plan_Account_vod__c,Cycle_Plan_vod__r.Territory_vod__c FROM Cycle_Plan_Target_vod__c WHERE Cycle_Plan_Account_vod__c IN:callmap.keyset() AND Cycle_Plan_vod__r.active_vod__c = true];
system.debug('cptlist>>>'+cptlist);
for(Cycle_Plan_Target_vod__c cpt: cptlist){
terrname.add(cpt.Cycle_Plan_vod__r.Territory_vod__c);
}system.debug('terrname>>'+terrname);
Map<string,id> utmap = new Map<string,id>();
for(territory ut: [Select id,name from Territory where territory.name in : terrname]){
utmap.put(ut.name,ut.id);
}
Map<id,List<id>> useraccmap = new Map<id,List<id>>();
Map<id,List<id>> accterrmap = new Map<id,List<id>>();
Map<id,List<Call2_vod__c>> finalmap = new Map<id,List<Call2_vod__c>>();
for(Cycle_Plan_Target_vod__c cpt: cptlist){
if(utmap.containskey(cpt.Cycle_Plan_vod__r.Territory_vod__c)){
if(!accterrmap.containsKey(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c))){
accterrmap.put(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c), new List<String>{cpt.Cycle_Plan_Account_vod__c});
}else{
List<id> i = new List<id>();
i = accterrmap.get(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c));
i.add(cpt.Cycle_Plan_Account_vod__c);
accterrmap.put(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c),i);
}
} }system.debug('accterrmap>>'+accterrmap);
Map<id,List<Call2_vod__c>> terrcallmap = new Map<id,List<Call2_vod__c>>();
for(Id tempid: accterrmap.keyset()){
List<id> tempidlist = accterrmap.get(tempid);
for(id i:tempidlist){
if(callmap.containsKey(i)){
if(!terrcallmap.containsKey(tempid)){
List<Call2_vod__c> i1 = new List<Call2_vod__c>();
i1.add(callmap.get(i));
terrcallmap.put(tempid,i1);
}
else{
List<Call2_vod__c> i2 = new List<Call2_vod__c>();
i2=terrcallmap.get(tempid);
i2.add(callmap.get(i));
terrcallmap.put(tempid,i2);
}
}
}
}system.debug('terrcallmap>>'+terrcallmap);
List<UserTerritory> utlist =[Select userid, territoryid from UserTerritory where territoryid in: terrcallmap.keyset()];
Map<id,id> useridterridmap = new Map<id,id>();
for(UserTerritory ut: utlist){
useridterridmap.put(ut.territoryid,ut.userid);
}system.debug('useridterridmap>>'+useridterridmap);
for(id i3: terrcallmap.keyset()){
if(useridterridmap.containskey(i3)){
finalmap.put(useridterridmap.get(i3),terrcallmap.get(i3));
}
}system.debug('finalmap>>>'+finalmap);
for(id i4: finalmap.keyset()){
system.debug('i4>>>'+i4);
List<Call2_vod__c> calldetail = finalmap.get(i4);
String concatenatedtext='';
for(Call2_vod__c c:calldetail){
concatenatedText+=c.Account_vod__r.name+' seen '+c.CMS_Submitted_DateTime__c.format()+ ' by '+c.owner.name+'\n';
if(c.Detailed_Products_vod__c != null){
concatenatedText= concatenatedText.removeEnd('\n');
concatenatedText+= ' ('+c.Detailed_Products_vod__c+' )'+'\n';
}
}
concatenatedText = concatenatedText.removeEnd('\n');
system.debug('concatenatedtext>>>>'+concatenatedText);
Alert_vod__c alert = new Alert_vod__c();
alert.Name = submittedCallHeader;
alert.Activation_Date_vod__c = system.now();
alert.Alert_Text_vod__c = concatenatedText;
alert.Expiration_Date_vod__c = system.now()+1;
alert.Public_vod__c = true;
alert.ownerid=i4;
alert.Priority_vod__c = 'Normal';
alertsubmittedcalllist.add(alert);
}
global class CMS_Batch_Alert_Submitted_Call implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
List<Pfizer_Country_Code_Setting__mdt> metadataList = [Select Label from Pfizer_Country_Code_Setting__mdt];
List<String> countrycodeList = new List<String>();
for(Pfizer_Country_Code_Setting__mdt mdt:metadataList){
countrycodeList.add(mdt.Label);
}
String query = 'SELECT id,CMS_Submitted_DateTime__c,Account_vod__c,Account_vod__r.name,ownerid,owner.name,Detailed_Products_vod__c FROM Call2_vod__c where Status_vod__c = \'Submitted_vod\' AND CMS_Submitted_DateTime__c = LAST_N_DAYS:7 and Account_vod__c !=null and CMS_Country_Code__c in : countrycodeList order by CMS_Submitted_DateTime__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject>scope) {
String submittedCallHeader = System.Label.CMS_Submittted_Calls_in_Last_7_Days_Alert_Header;
system.debug('submittedCallHeader>>'+submittedCallHeader);
List<Call2_vod__c> callList = (List<Call2_vod__c>) scope;
system.debug('call list>>>>'+calllist);
List<Alert_vod__c> alertsubmittedcalllist = new List<Alert_vod__c>();
Map<Id,Call2_vod__c> callmap = new Map<Id,Call2_vod__c>();
for(Call2_vod__c c:calllist){
if(!callmap.containsKey(c.account_vod__c)){
callmap.put(c.Account_vod__c,c);
}
else{
Call2_vod__c cc = callmap.get(c.account_vod__c);
if(cc.CMS_Submitted_DateTime__c < c.CMS_Submitted_DateTime__c) {
callmap.remove(c.account_vod__c);
}
callmap.put(c.account_vod__c,c);
}}
system.debug('callmap>>>'+callmap);
Set<String> terrname = new set<String>();
List<Cycle_Plan_Target_vod__c> cptlist = [SELECT Cycle_Plan_Account_vod__c,Cycle_Plan_vod__r.Territory_vod__c FROM Cycle_Plan_Target_vod__c WHERE Cycle_Plan_Account_vod__c IN:callmap.keyset() AND Cycle_Plan_vod__r.active_vod__c = true];
system.debug('cptlist>>>'+cptlist);
for(Cycle_Plan_Target_vod__c cpt: cptlist){
terrname.add(cpt.Cycle_Plan_vod__r.Territory_vod__c);
}system.debug('terrname>>'+terrname);
Map<string,id> utmap = new Map<string,id>();
for(territory ut: [Select id,name from Territory where territory.name in : terrname]){
utmap.put(ut.name,ut.id);
}
Map<id,List<id>> useraccmap = new Map<id,List<id>>();
Map<id,List<id>> accterrmap = new Map<id,List<id>>();
Map<id,List<Call2_vod__c>> finalmap = new Map<id,List<Call2_vod__c>>();
for(Cycle_Plan_Target_vod__c cpt: cptlist){
if(utmap.containskey(cpt.Cycle_Plan_vod__r.Territory_vod__c)){
if(!accterrmap.containsKey(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c))){
accterrmap.put(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c), new List<String>{cpt.Cycle_Plan_Account_vod__c});
}else{
List<id> i = new List<id>();
i = accterrmap.get(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c));
i.add(cpt.Cycle_Plan_Account_vod__c);
accterrmap.put(utmap.get(cpt.Cycle_Plan_vod__r.Territory_vod__c),i);
}
} }system.debug('accterrmap>>'+accterrmap);
Map<id,List<Call2_vod__c>> terrcallmap = new Map<id,List<Call2_vod__c>>();
for(Id tempid: accterrmap.keyset()){
List<id> tempidlist = accterrmap.get(tempid);
for(id i:tempidlist){
if(callmap.containsKey(i)){
if(!terrcallmap.containsKey(tempid)){
List<Call2_vod__c> i1 = new List<Call2_vod__c>();
i1.add(callmap.get(i));
terrcallmap.put(tempid,i1);
}
else{
List<Call2_vod__c> i2 = new List<Call2_vod__c>();
i2=terrcallmap.get(tempid);
i2.add(callmap.get(i));
terrcallmap.put(tempid,i2);
}
}
}
}system.debug('terrcallmap>>'+terrcallmap);
List<UserTerritory> utlist =[Select userid, territoryid from UserTerritory where territoryid in: terrcallmap.keyset()];
Map<id,id> useridterridmap = new Map<id,id>();
for(UserTerritory ut: utlist){
useridterridmap.put(ut.territoryid,ut.userid);
}system.debug('useridterridmap>>'+useridterridmap);
for(id i3: terrcallmap.keyset()){
if(useridterridmap.containskey(i3)){
finalmap.put(useridterridmap.get(i3),terrcallmap.get(i3));
}
}system.debug('finalmap>>>'+finalmap);
for(id i4: finalmap.keyset()){
system.debug('i4>>>'+i4);
List<Call2_vod__c> calldetail = finalmap.get(i4);
String concatenatedtext='';
for(Call2_vod__c c:calldetail){
concatenatedText+=c.Account_vod__r.name+' seen '+c.CMS_Submitted_DateTime__c.format()+ ' by '+c.owner.name+'\n';
if(c.Detailed_Products_vod__c != null){
concatenatedText= concatenatedText.removeEnd('\n');
concatenatedText+= ' ('+c.Detailed_Products_vod__c+' )'+'\n';
}
}
concatenatedText = concatenatedText.removeEnd('\n');
system.debug('concatenatedtext>>>>'+concatenatedText);
Alert_vod__c alert = new Alert_vod__c();
alert.Name = submittedCallHeader;
alert.Activation_Date_vod__c = system.now();
alert.Alert_Text_vod__c = concatenatedText;
alert.Expiration_Date_vod__c = system.now()+1;
alert.Public_vod__c = true;
alert.ownerid=i4;
alert.Priority_vod__c = 'Normal';
alertsubmittedcalllist.add(alert);
}