• F Smoak
  • NEWBIE
  • 34 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 33
    Questions
  • 43
    Replies
I am trying to remove extra space between images in the community page. Can anyone please help on this?
code snippet:
<aura:iteration items="{!v.dashboardWrapper.ProgramInfo}" var="q">
                                <aura:if isTrue="{!(q.Label == activeProgram.label)}">
                                    <a data-program="{!activeProgram.label}" class="darkish-green" href="javascrip:void(0);" onclick="{!c.handleProgramClick}">
                                        <img src="{!$Resource.programicons +'/' + q.Icon__c}" style="background-color: white;"/>
                                    </a>
                                </aura:if>
                            
                            </aura:iteration>
 
Hi 

I have a custom object X. On this object when I navigate via tab, I dont see new button and I want to add the button. But when I check Lightning Record page / search layout I am unable to figure out how to proceed! Please help!
Hi,

I have a req where I am automating creation of records for object A. So I have basically added a trigger(after insert,after update) on object B ( wh/ich contains object A Lookup) which automates creation of object A once some attributes(newly created on B to have attributes populated for creation of A) populated on B and also populates the same lookup with obj A ID newly automated. This also handles that when obj B is updated, marks the updates in obj A to keep both in sync. However end user has option to manually create obj A records so I wanted to ensure obj A changes reflect on obj B. But I think this will be recursive loop and wont be feasible. Is there any option to achieve this? Please help!
Hello,

 I am creating after insert trigger in obj : CMS_Rule__c which checks certain attributes and creates a record for another object MC_Cycle_vod__c . This part is working fine, but I need to map newly created MC_Cycle_vod__c record ID into same object CMS_Rule__c lookup field as CMS_Rule__c  object has a lookup relationship with MC_Cycle_vod__c object. I am stuck here and unable to correctly map newly record ID to correct CMS_Rule__c. Any help would be really apreciated as I can move forward with the code! Please find my code below:

trigger CMS_Create_MC_Cycle on CMS_Rule__c (after Insert) {
List<MC_Cycle_vod__c> cycleList = new List<MC_Cycle_vod__c>();
Map<id,MC_Cycle_vod__c> updatepoaList = new Map<id,MC_Cycle_vod__c>();
List<CMS_Rule__c> poaList = [Select id,CMS_Cycle_Name__c,CMS_Country_Code__c,CMS_MC_Cycle__c,CMS_Cycle_Start_Date__c,CMS_Cycle_End_Date__c FROM CMS_Rule__c WHERE id in: trigger.new and CMS_Status__c='Draft' and CMS_Is_Processed__c=false];
for(CMS_Rule__c rulerec:poaList){
MC_Cycle_vod__c cyclerec = new MC_Cycle_vod__c();
cyclerec.Name=rulerec.CMS_Cycle_Name__c;
cyclerec.CMS_Country_Code__c = rulerec.CMS_Country_Code__c;
cyclerec.Start_Date_vod__c = rulerec.CMS_Cycle_Start_Date__c;
cyclerec.End_Date_vod__c = rulerec.CMS_Cycle_End_Date__c;
cyclerec.Status_vod__c='Planned_vod';
cycleList.add(cyclerec);
}
insert cycleList;
Set<id> mccycleId=new Set<id>();
for(MC_Cycle_vod__c mccycleRec: cycleList){
mccycleId.add(mccycleRec.id); //newly inserted ID i need to map to correct record which is running in for loop
}
}
Hi,

I have written a batch class which inserts "mccp" list based on "poaSet" Now for newly created mccp from batch class I need to insert "newRuleList" which has lookup to mccp id and poa id. I have invoked 2nd batch from 1st batch finish method but when i execute the first batch, both runs successfully.For Batch 1 4 MCCP inserted, whereas for BAtch 2 instead of 4 rulelist only 1 is inserted. I am unable to debug why only one MCCP is picked up to create rule list.Please help as I am in a fix!

Finish method of batch 1:
global void finish(Database.BatchableContext BC){
if(poaSet.size()>0 && mccp.size()>0){
CMS_Batch_Insert_MC_Cycle_Plan_Rule_List rulebatch = new CMS_Batch_Insert_MC_Cycle_Plan_Rule_List(poaSet,mccp);
Database.executeBatch(rulebatch, 200);
}
}

Batch 2:

global class CMS_Batch_Insert_MC_Cycle_Plan_Rule_List implements Database.Batchable<sObject>,Database.Stateful{
Map<id,id> poaCycle = New Map<id,id>();
Map<id,id> mccpCycle = New Map<id,id>();
Map<id,id>poamccp= new Map<id,id>();
Set<id> poaSet = new Set<id>();
List<MC_Cycle_Plan_vod__c> mccp= new List<MC_Cycle_Plan_vod__c>();
public CMS_Batch_Insert_MC_Cycle_Plan_Rule_List(Set<Id> poaSet, List<MC_Cycle_Plan_vod__c> mccp)
{
this.poaSet = poaSet;
this.mccp = mccp;}
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator('SELECT id,CMS_MC_Cycle__c from CMS_Rule__c where id in: poaSet');
}
global void execute(Database.BatchableContext BC, List<sobject> scope){
List<CMS_Rule_Status__c> newruleList = new List<CMS_Rule_Status__c>();
for(CMS_Rule__c poaRecs:(List<CMS_Rule__c>)scope){
poaCycle.put(poaRecs.CMS_MC_Cycle__c,poaRecs.id);
} system.debug('poacycle>>'+poaCycle);
List<MC_Cycle_Plan_vod__c> mccpList = [Select id,cycle_vod__c from MC_Cycle_Plan_vod__c where cycle_vod__c in: poaCycle.keyset()];
for(MC_Cycle_Plan_vod__c mcRecs: mccpList){
mccpCycle.put(mcRecs.cycle_vod__c,mcRecs.id);
}system.debug('mccpCycle>>'+mccpCycle);
for(Id cycid:mccpCycle.keySet()){
if(poaCycle.containsKey(cycid)){
poamccp.put(poaCycle.get(cycid),mccpCycle.get(cycid));
}system.debug('poamccp>>'+poamccp);
}
if(poamccp.size()>0){
List<CMS_Rule_Status__c> existingRecs = [Select id,MC_Cycle_Plan__c,Rule_Name__c from CMS_Rule_Status__c where Rule_Name__c in : poamccp.keyset()];
if(existingRecs.size()>0){
for(CMS_Rule_Status__c existingrule:existingRecs){
if(poamccp.containsKey(existingrule.Rule_Name__c)){
poamccp.remove(existingrule.Rule_Name__c);
}
}}}
if(poamccp.size()>0){
for(id j1:poamccp.keyset()){
CMS_Rule_Status__c rulelist = new CMS_Rule_Status__c();
rulelist.MC_Cycle_Plan__c=poamccp.get(j1);
rulelist.Rule_Name__c=j1;
rulelist.Status__c='In Progress';
newRuleList.add(rulelist);
}}
if(newRuleList.size()>0){
insert newRuleList;
}
}
global void finish(Database.BatchableContext BC){
}
}
I have created an after Insert trigger on SObject which creates records for another object based on SObject created from csutom vf page and apex. 
While testing, I see that trigger runs successfully and records are created nce Sobject records created from data loader but when I created Sobject from custom page, trigger doesnt fire and debug logs dont show any information. Any helps will be appreciated!
Hi I have written an after insert record which validates when CMS_Rule_Line_Item__c is created in bulk for a particular CMS_Rule__c (which has a lookup to CMS_MC_Cycle__c), create MC_Cycle_Plan_vod__c record. My debug log size is 10mb+ and qury rows count = 11k+ and my CPU Time is 3.5k I have just tested small records and inserted 174 recs. I would like to bring all these limits under control, but I cant seem to get rid of nested for loops. Any help is much appreciated!
Code:

trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
    List<Territory> territoryList = new List<Territory>();
    List<MC_Cycle_Plan_vod__c> mccp =  new List<MC_Cycle_Plan_vod__c>();
    Map<id,Set<String>> poateamMap =  new Map<id,Set<String>>(); //cycleid vs set of team
    List<CMS_Rule_Line_Item__c> cbList= [Select id,CMS_Team__c,Rule_Name__c,Rule_Name__r.CMS_MC_Cycle__c from CMS_Rule_Line_Item__c
                                         where id in: trigger.new];
    Set<String> teamSet = new Set<String>();
    for(CMS_Rule_Line_Item__c crRecord: cbList){
        if(!poateamMap.containsKey(crRecord.Rule_Name__r.CMS_MC_Cycle__c)){
            poateamMap.put(crRecord.Rule_Name__r.CMS_MC_Cycle__c,new Set<String>{crRecord.CMS_Team__c});
            teamSet.add(crRecord.CMS_Team__c);
        }
        else{
                poateamMap.get(crRecord.Rule_Name__r.CMS_MC_Cycle__c).add(crRecord.CMS_Team__c);
                teamSet.add(crRecord.CMS_Team__c);
        } }
    system.debug('poa vs team list>>>'+poateamMap.size() +poateamMap);
   
    Map<String,List<Territory>> teamterrMap = new Map<String,List<Territory>>(); //team vs list of territory
    List<Territory> teamterrList =  [Select id,name,CMS_Salesforce__c from Territory where CMS_Salesforce__c in: teamSet];
    Set<id> terrSet = new Set<id>();
    Map<id,id> terruseridMap =new Map<id,id>();
   
            for(Territory t1:teamterrList){
            if(teamSet.contains(t1.CMS_Salesforce__c)){
                if(!teamterrMap.containsKey(t1.CMS_Salesforce__c)){
                teamterrMap.put(t1.CMS_Salesforce__c,new List<Territory>{t1});
                    terrSet.add(t1.id);
            }
            else{
                teamterrMap.get(t1.CMS_Salesforce__c).add(t1);
                terrSet.add(t1.id);
            }  
            }
        }
    Map<id,id> userterridMap =new Map<id,id>(); //userid with corresponding territoryid
    for(UserTerritory ut:[Select territoryid,userid from UserTerritory where territoryid in : terrSet]){
        userterridMap.put(ut.userid,ut.territoryid);
        terruseridMap.put(ut.territoryid,ut.userid);
    }
    Map<id,string> userterrMap= new Map<id,string>(); // territoryid with corresponding username
    for(User u:[Select id,name from User where id = : userterridMap.keyset()]){
        userterrMap.put(userterridMap.get(u.id),u.name);
    }
   
  //  system.debug('team vs terr list>>>'+teamterrMap.size() +teamterrMap);
    Map<id,List<Territory>> poaterrMap = new Map<id,List<Territory>>(); //cycleid with corresponding territory ids
    for(Id i1:poateamMap.keySet()){
        for(String s1:poateamMap.get(i1)){
            if(teamterrMap.containsKey(s1)){
                if(!poaterrMap.containsKey(i1)){
                    List<Territory> tList = new List<Territory>();
                    tList=teamterrMap.get(s1);
                    poaterrMap.put(i1,tList);
                }
                else{
                    List<Territory> tList2 = new List<Territory>();
                    tList2=teamterrMap.get(s1);
                    for(Territory tt:tList2){
                    poaterrMap.get(i1).add(tt);
                    }
                }
            }
        }
    }
    //system.debug('poa vs terr list>>>'+poaterrMap.size() +poaterrMap);
   
    List<MC_Cycle_Plan_vod__c> existingcycleMccp = [Select id,Cycle_vod__c,Territory_vod__c from MC_Cycle_Plan_vod__c where Cycle_vod__c in:poaterrMap.keyset()];
    Map<id,List<Territory>> finalMap = new Map<id,List<Territory>>();
    if(existingcycleMccp.size()>0){
    for(MC_Cycle_Plan_vod__c mcplan: existingcycleMccp){
        if(!poaterrMap.containsKey(mcplan.Cycle_vod__c)){
                for(Territory t2:poaterrMap.get(mcplan.Cycle_vod__c)){
                    if(t2.name!=mcplan.Territory_vod__c){
                        if(!finalMap.containsKey(mcplan.Cycle_vod__c)){
                            finalMap.put(mcplan.Cycle_vod__c, new List<Territory>{t2});
                        }
                        else{
                            finalMap.get(mcplan.Cycle_vod__c).add(t2);
                        }
                    }
                }
        }
    } }
    else{
        finalMap.putAll(poaterrMap);
    }
//system.debug('finalMap list>>>'+finalMap.size() +finalMap);
   
    List<MC_Cycle_vod__c> mccycleList = new List<MC_Cycle_vod__c>();
    mccycleList= [Select Id,Start_date_vod__c from MC_Cycle_vod__c where Id in: finalMap.keyset()];
    List<CMS_MC_Cycle_Month__mdt> mdtList = new List<CMS_MC_Cycle_Month__mdt>();
    mdtList= [Select Id,DeveloperName,CMS_Month_Number__c from CMS_MC_Cycle_Month__mdt];
   
    try{
        if(trigger.isInsert && finalMap.size()>0){
    for(Id rule:finalMap.keyset()){
        Integer monthval=null;
        Integer CycleYear=null;
        String CycleMonth ='';
        String mccpName = '';
        for(MC_Cycle_vod__c mccyclerec: mccycleList){
            if(mccyclerec.id==rule){
            monthval=mccyclerec.Start_date_vod__c.month();
            CycleYear = mccyclerec.Start_date_vod__c.year();
            for(CMS_MC_Cycle_Month__mdt monthmdt : mdtList){
                if(monthmdt.CMS_Month_Number__c==monthval){
                CycleMonth = monthmdt.DeveloperName;
                mccpName= 'MCCP_'+cycleMonth+'_'+cycleYear+'_';
                }}
            }}
        for(Territory terrname: finalMap.get(rule)){
            if(terruseridmap.containsKey(terrname.id)){
            MC_Cycle_Plan_vod__c mcRecord =  new MC_Cycle_Plan_vod__c();
            mcRecord.Cycle_vod__c= rule;
            mcRecord.CMS_Team__c=terrname.CMS_Salesforce__c;
            mcRecord.Territory_vod__c= terrname.name;
            mcRecord.Status_vod__c='In Progress';
            mcRecord.Ownerid=terruseridMap.get(terrname.id);
               
            if(userterrMap.containsKey(terrname.id)){
                    mcRecord.Name=mccpName+userterrMap.get(terrname.id);
                }
            mccp.add(mcRecord);
            }} }
    if(mccp.size()>0){
        insert mccp;
    }  } }
    catch (DmlException e) {
        System.debug('A DML exception has occurred: ' +e.getMessage() +e.getLineNumber());
    }          
}
Hi

I am writing a trigger wherein as first step I need to create a map containing its parent id, Set of text field values which are possibly duplicates for that object records.
Code:
trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
        Map<id,Set<String>> poateamMap =  new Map<id,Set<String>>(); //poaid vs set of team
    List<CMS_Rule_Line_Item__c> cbList= trigger.new;
        for(CMS_Rule_Line_Item__c crRecord: cbList){
        if(!poateamMap.containsKey(crRecord.Rule_Name__c)){
            poateamMap.put(crRecord.Rule_Name__c,new Set<String>{crRecord.CMS_Team__c});
            }
            else{
                Set<String> str = new Set<String>();
                str =  poateamMap.get(crRecord.Rule_Name__c);
                if(str != crRecord.CMS_Team__c) {
                   poateamMap.put(crRecord.Rule_Name__c,crRecord.CMS_Team__c);
            }
            } }

Here Iwould like to ensure that Rule_Name__c (stores parent id) has corresponding set of records having only one distinct team value for it in that set.
I am missing something but cannot figure out. Please help!
  • September 28, 2020
  • Like
  • 0
I have written a beow code where I have a text field on my object which populates duplicate values of territory name. I need to retrieve a set of this field value (in form of string as the field data type is text) but getting following error.- DML requires SObject or SObject list type: Set<String> in below bold line
Please help!
code:
trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
    List<Territory> territoryList = new List<Territory>();
    List<MC_Cycle_Plan_vod__c> mccp =  new List<MC_Cycle_Plan_vod__c>();
    Set<String> teamList = new Set<String>();
        for(CMS_Rule_Line_Item__c crRecord: Trigger.new){
        teamList.add(crRecord.CMS_Team__c);
    }
       insert teamList;
}
 
  • September 28, 2020
  • Like
  • 0
I have russian values for picklist field values in my org and I would like to query these out and show it to end users as records in custom object. But I dont see anyway to query in translation workbench. ANy help would be appreciated!
I am creating a batch class that queries on a call object and filters all the latest call records to populate this information on a custom object. My call records satisfying query is 6000 records so what happens is that the call records are divided across 3 batches and creates 3 records whereas I want this combined in single record. I tried to implement stateful method and insert in finish method. But this does not help,please help on this!
global class CMS_Batch_Alert_Submitted_Call implements Database.Batchable<sObject>,Database.Stateful{
    List<Alert_vod__c> alertsubmittedcalllist = new List<Alert_vod__c>();
    global Database.QueryLocator start(Database.BatchableContext BC) {
       
        List<String> countrycodeList = new List<String>();
        for(Pfizer_Country_Code_Setting__mdt mdt:[Select Label from Pfizer_Country_Code_Setting__mdt]){
            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';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject>scope) {
        List<Call2_vod__c> callList = (List<Call2_vod__c>) scope;
        system.debug('call list>>>>'+calllist);
        List<Pfizer_Submitted_Call_Alert_Text_Values__mdt> langlist = new List<Pfizer_Submitted_Call_Alert_Text_Values__mdt>();
        for(Pfizer_Submitted_Call_Alert_Text_Values__mdt langmdt : [Select Id,CMS_Submitted_Call_Alert_Header__c,CMS_Submitted_Call_Alert_Text_Header__c,CMS_Submitted_Call_By__c,CMS_Submitted_Call_Language_Key__c,CMS_Seen__c from Pfizer_Submitted_Call_Alert_Text_Values__mdt]){
            langlist.add(langmdt);
        } 
        //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);
            String userlang = [Select languagelocalekey from User where id =: i4].languagelocalekey;
            String concatenatedtext='';
            String submittedCallHeader='';
            Integer size = 0;
            for(Pfizer_Submitted_Call_Alert_Text_Values__mdt lmdt : langlist){
               if(lmdt.CMS_Submitted_Call_Language_Key__c == userlang){
                  submittedCallHeader = lmdt.CMS_Submitted_Call_Alert_Header__c;
                   concatenatedText=lmdt.CMS_Submitted_Call_Alert_Text_Header__c+'\n';
           for(Call2_vod__c c:finalmap.get(i4)){ 
               if(c.ownerid != i4){
                   size=size+1;
               concatenatedText+=c.Account_vod__r.name+' '+lmdt.CMS_Seen__c+' '+c.CMS_Submitted_DateTime__c.format('MMMMM').substring(0,3)+' '+c.CMS_Submitted_DateTime__c.day()+' '+lmdt.CMS_Submitted_Call_By__c+' '+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');
               }}
            if(size>0){
            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';
            alert.Dismissible_vod__c = true;
            alertsubmittedcalllist.add(alert);
            }}
        
    }
   
    global void finish(Database.BatchableContext BC) {
        if(alertsubmittedcalllist.size()>0)
        {
            insert alertsubmittedcalllist;
            system.debug('alert list>>>>'+alertsubmittedcalllist +alertsubmittedcalllist.size());
        }
    }
}
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);
                }
I have requirement to create an alert everyday displaying list of calls submitted by users sharing same set of accounts over last 7 days. But the text field should display selective values for user based on its accountshare.My code is in raw state written below. I am stuck in selectively displaying user the alert record field value
Say if result set is:
C1 created by U1 on A1
C2 created by U2 on A1
C3 created by U3 on A2
C4 created by U4 on A3

if U1 has A2,  A1 in account share, he should see single record with text field showing as:
C1 created by U1 on A1
C2 created by U2 on A1
C3 created by U3 on A2 
if U2 has A3,  A1 in account share, he should see single record with text field showing as:
C1 created by U1 on A1
C2 created by U2 on A1
C4 created by U4 on A3

Please find my code below:
global class BatchCreateAlertforCalls implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {  
        
        String query = 'SELECT Id,CMS_Submitted_DateTime__c,Account_vod__r.name,createdby.name FROM Call2_vod__c where Status_vod__c = \'Submitted_vod\' AND CMS_Submitted_DateTime__c >= N_DAYS_AGO:7 AND OwnerId!=\'005U0000001vQ0a\'';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject>scope) {
        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>();
        List<Alert_vod__Share> alsharelist = new List<Alert_vod__Share>();
        String concatenatedText='';
        for(Call2_vod__c c: callList){
       concatenatedText+=c.Account_vod__r.name+' seen by '+c.createdby.name + ' on '+c.CMS_Submitted_DateTime__c.format()+'\n';            
        }
        concatenatedText = concatenatedText.removeEnd('\n');
        system.debug('concatenatedtext>>>>'+concatenatedText);

        if(callList.size()!=null && callList.size()>0){
            Alert_vod__c alert = new Alert_vod__c();
            alert.Name = 'Calls Submitted in last 7 days';
            alert.Activation_Date_vod__c = system.today();
            alert.Alert_Text_vod__c = concatenatedText;
            alert.Expiration_Date_vod__c = system.today()+1;
            alert.Created_by_batch__c = true;
            alertsubmittedcalllist.add(alert);
        }
        if(alertsubmittedcalllist.size() >0)
        {
            insert alertsubmittedcalllist;
            system.debug('alert list>>>>'+alertsubmittedcalllist);
        }
        
        List<Alert_vod__c> deleteAlerts = new List<Alert_vod__c>();
        deleteAlerts = [Select Id from Alert_vod__c where Expiration_Date_vod__c <= today and Created_by_batch__c =true ];
        if(deleteAlerts.size()>0){
            delete deleteAlerts;
        }
    }
    }
    global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
    }
}
  • September 30, 2019
  • Like
  • 0
I have to delete alerts whne expiration datetime has reached today's datetime
My expiration datetime is showing as 2019-10-05T00:00:00.000Z
I want to delete this record on 5th Oct but I am getting unknown error parsing query when I execute in query editor:
Select Id from Alert_vod__c where Expiration_Date_vod__c <= system.now()

Please help.

 
  • September 28, 2019
  • Like
  • 0
share records with the end user when created by batch class
I have a requirement:

For an account in user's territory, we have calls created. Now based on this I need to create alerts where user can view alerts showing his account got calls on which date by which user in last 7 days. For this I need to create a batch but since all alerts are created by admin end user do not have access to alerts. How to fix this?
Please find my code below:

global class BatchCreateAlertforCalls implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {  
    
    String query = 'SELECT Id,Call_Date_vod__c,Account_vod__c,createdby.name FROM Call2_vod__c where Status_vod__c = \'Submitted_vod\' AND Call_Date_vod__c = N_DAYS_AGO:7 AND OwnerId!=\'005U0000001vQ0a\'';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject>scope) {
        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>();
        for(Call2_vod__c call: callList){
         Alert_vod__c alert = new Alert_vod__c();
            alert.Activation_Date_vod__c = system.now();
            alert.Alert_Text_vod__c = call.Account_vod__c+' seen by '+call.createdby.name;
            alert.Link_Reference_vod__c =call.Id;
            alert.Expiration_Date_vod__c = system.now()+1;
            alertsubmittedcalllist.add(alert);
        }
        if(alertsubmittedcalllist.size() >0)
        {
            insert alertsubmittedcalllist;
            system.debug('alert list>>>>'+alertsubmittedcalllist);
        }
}
     global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}
  • September 27, 2019
  • Like
  • 0
I am trying to create a new territory and assign it to my existing 3 child territories as parent. WHile deploying to target org, I am getting above error in validating change sets for 2 of my 3 child territories.
Kindly let me know how to fix this.
  • September 13, 2019
  • Like
  • 0
I am trying to retrieve user IDs which do not belong to those territories whose names starts with IT_CH, but getting error "Unknown error parsing query" in dev console query editor.
Please note I need to use this as a single query and not via executing a class having for loops traversing from Territory to UserTerritory to User:

Select Id from User where Id in (Select UserID from UserTerritory where NOT TerritoryID.name LIKE 'IT_CH%'))

Please help.
  • September 05, 2019
  • Like
  • 0
I have a Territory "Sales" under which I have a hierarchy of children territories.
I need to have list of users right from under Sales to bottom-most level. Please help with this.

Hierarchy is somwhat like:
Parent : Sales
Child : S1, S2
S1 has : SS1, SS2,......
S2 has : SS99,SS98,.....
SS1 has : SSS1,.....
and so on
  • September 05, 2019
  • Like
  • 0
Hi Guys,

I have written a trigger. The objective is if No See on Account is TRUE, Zip code of address appends to Address name and in turn zip code updates to 'nosee'. My trigger is almost working with one small defect that is address name is getting appended to zip numeric value and new value ie, no see. How doI correct it to display only old zip numeric value . Please find code below:

trigger TKD_Update_Address_Zip_Code on Account (after update) {
Set<Id> accountIds = new Set<Id>();
for(Account newAcc: Trigger.new){
    Account oldAcc = Trigger.oldMap.get(newAcc.Id);

    if(oldAcc.TKD_No_See__c != newAcc.TKD_No_See__c && newAcc.TKD_No_See__c == true) {
      accountIds.add(newAcc.Id);  
      system.debug('id'+accountIds);
       }
    }
     List<Address_vod__c> addressAddressLine = [select Zip_vod__c, Name from Address_vod__c where Account_vod__c in :accountIds];
     
     for(Address_vod__c AddressLine:addressAddressLine){
     
        AddressLine.Name= AddressLine.Name + ',' + AddressLine.Zip_vod__c;        
     }
     
    if(addressAddressLine.isEmpty()== false)
        update addressAddressLine;
    
    List<Address_vod__c> addressZipCodes = [select Zip_vod__c from Address_vod__c where Account_vod__c in :accountIds];
         for(Address_vod__c zip:addressZipCodes){
             
             zip.Zip_vod__c='no_see';
    
     }
     
     if(addressZipCodes.isEmpty()== false)
        update addressZipCodes;
     
}
I have an obj A which loads all Products loaded for an account having M/D relationship. I need to pull value of Product Segment field for a particular product M(from obj A) and display it on Account detail page. How can I do that using a trigger?
Note: Product M -- this value is coming from lookup field from a different obj X.
Hi

I am writing a trigger wherein as first step I need to create a map containing its parent id, Set of text field values which are possibly duplicates for that object records.
Code:
trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
        Map<id,Set<String>> poateamMap =  new Map<id,Set<String>>(); //poaid vs set of team
    List<CMS_Rule_Line_Item__c> cbList= trigger.new;
        for(CMS_Rule_Line_Item__c crRecord: cbList){
        if(!poateamMap.containsKey(crRecord.Rule_Name__c)){
            poateamMap.put(crRecord.Rule_Name__c,new Set<String>{crRecord.CMS_Team__c});
            }
            else{
                Set<String> str = new Set<String>();
                str =  poateamMap.get(crRecord.Rule_Name__c);
                if(str != crRecord.CMS_Team__c) {
                   poateamMap.put(crRecord.Rule_Name__c,crRecord.CMS_Team__c);
            }
            } }

Here Iwould like to ensure that Rule_Name__c (stores parent id) has corresponding set of records having only one distinct team value for it in that set.
I am missing something but cannot figure out. Please help!
  • September 28, 2020
  • Like
  • 0
I have written a beow code where I have a text field on my object which populates duplicate values of territory name. I need to retrieve a set of this field value (in form of string as the field data type is text) but getting following error.- DML requires SObject or SObject list type: Set<String> in below bold line
Please help!
code:
trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
    List<Territory> territoryList = new List<Territory>();
    List<MC_Cycle_Plan_vod__c> mccp =  new List<MC_Cycle_Plan_vod__c>();
    Set<String> teamList = new Set<String>();
        for(CMS_Rule_Line_Item__c crRecord: Trigger.new){
        teamList.add(crRecord.CMS_Team__c);
    }
       insert teamList;
}
 
  • September 28, 2020
  • Like
  • 0
I have russian values for picklist field values in my org and I would like to query these out and show it to end users as records in custom object. But I dont see anyway to query in translation workbench. ANy help would be appreciated!
I have to delete alerts whne expiration datetime has reached today's datetime
My expiration datetime is showing as 2019-10-05T00:00:00.000Z
I want to delete this record on 5th Oct but I am getting unknown error parsing query when I execute in query editor:
Select Id from Alert_vod__c where Expiration_Date_vod__c <= system.now()

Please help.

 
  • September 28, 2019
  • Like
  • 0
share records with the end user when created by batch class
I have a requirement:

For an account in user's territory, we have calls created. Now based on this I need to create alerts where user can view alerts showing his account got calls on which date by which user in last 7 days. For this I need to create a batch but since all alerts are created by admin end user do not have access to alerts. How to fix this?
Please find my code below:

global class BatchCreateAlertforCalls implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {  
    
    String query = 'SELECT Id,Call_Date_vod__c,Account_vod__c,createdby.name FROM Call2_vod__c where Status_vod__c = \'Submitted_vod\' AND Call_Date_vod__c = N_DAYS_AGO:7 AND OwnerId!=\'005U0000001vQ0a\'';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject>scope) {
        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>();
        for(Call2_vod__c call: callList){
         Alert_vod__c alert = new Alert_vod__c();
            alert.Activation_Date_vod__c = system.now();
            alert.Alert_Text_vod__c = call.Account_vod__c+' seen by '+call.createdby.name;
            alert.Link_Reference_vod__c =call.Id;
            alert.Expiration_Date_vod__c = system.now()+1;
            alertsubmittedcalllist.add(alert);
        }
        if(alertsubmittedcalllist.size() >0)
        {
            insert alertsubmittedcalllist;
            system.debug('alert list>>>>'+alertsubmittedcalllist);
        }
}
     global void finish(Database.BatchableContext BC) {
        // execute any post-processing operations
  }
}
  • September 27, 2019
  • Like
  • 0
I am trying to create a new territory and assign it to my existing 3 child territories as parent. WHile deploying to target org, I am getting above error in validating change sets for 2 of my 3 child territories.
Kindly let me know how to fix this.
  • September 13, 2019
  • Like
  • 0
I am trying to retrieve user IDs which do not belong to those territories whose names starts with IT_CH, but getting error "Unknown error parsing query" in dev console query editor.
Please note I need to use this as a single query and not via executing a class having for loops traversing from Territory to UserTerritory to User:

Select Id from User where Id in (Select UserID from UserTerritory where NOT TerritoryID.name LIKE 'IT_CH%'))

Please help.
  • September 05, 2019
  • Like
  • 0
I am new to salesforce, I have some confussion with Apex managed sharing, where we can use exactly in real time?

Please clear my confussion..

Thanks in advance

I am stuck on writing a query to facilitate Congra Composer.  For reasons beyond this request, I need to 'dedupe' a query of data as well as put it into a set order.  I can easily do one or the other but not both.  If I do an ORDER BY I get all results using the following SOQL:

SELECT Group__c, Order__c FROM OpportunityLineItem WHERE Opportunity.Id = 'xxxxxxxxxxxx' Order by Order__c

Which returns:

1   Eggs
1   Eggs
2   Tomatoes
2   Tomatoes
3   Bananas
3   Bananas

However that does not allow me to 'dedupe' as i would if I used the following SOQL:

SELECT Group__c FROM OpportunityLineItem WHERE Opportunity.Id = 'xxxxxxxxxxx' GROUP BY Group__c

Which returns:

Eggs
Tomatoes
Bananas

So... When I put it all together in hopes of getting (1 Eggs, 2 Tomatoes, 3 Bananas) with the following SOQL:

SELECT MAX(Order__c), Group__c FROM OpportunityLineItem WHERE Opportunity.Id = '0064000000Rw0ea' GROUP BY Group__c ORDER BY Order__c

I get various "MALFORMED_QUERY: Ordered field must be grouped or aggregated: Order__c" Errors

Any ideas on how to achieve an ordered and distinct (deduped) query?

 

So I'm trying to do an aggregate query in Batch Apex and of course I'm running into the error "Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch" which is useless since of course the whole idea of an aggregation is get everything you need without a LIMIT.

 

I tried using the scope parameter on database.executeBatch because the documentation implies that it changes the batch size so I tried 3,000 since that is the quantity of records I have, but I still got the querymore error.

 

It looks like aggregate queries really cannot be used in Batch Apex.  Oh sure, for 20 records maybe, but not for 200+, i.e. the real world.  Can anyone confirm that?

 

Also, what does the scope parameter on database.executeBatch really do?  Does it only throttle down the batch size, or can you use it to throttle up the size?  If so, then why doesn't it work for aggregate queries?

 

Thanks

David

 

 

Hi,
in the Winter'09 release notes it says "Custom labels are custom text values, up to 1,000 characters in length, that can be accessed from Apex classes or Visualforce pages".
I could easily find how to access these labels from a visualforce page, but nowhere I can find how to access them from an apex class.
I need this because I have a class that dynamically generates labels for a certain table in a vf page. But I want to use Custom Labels (and the translation workbench) to get these translated in various languages.
Is there an object, something like Label with a static function like 'getLabel(String)'? Or is this not released in Winter '09?
  • September 30, 2008
  • Like
  • 0