-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
33Questions
-
43Replies
remove extra white space between two images
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>
-
- F Smoak
- May 10, 2022
- Like
- 0
- Continue reading or reply
display standard new button on lightning page
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!
-
- F Smoak
- June 24, 2021
- Like
- 0
- Continue reading or reply
Update child records based on update in parent record and vice versa
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!
-
- F Smoak
- January 21, 2021
- Like
- 0
- Continue reading or reply
Add newly inserted record's ID to corresponding record lookup in after insert trigger
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
}
}
-
- F Smoak
- October 22, 2020
- Like
- 0
- Continue reading or reply
pass collection from one batch to another
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){
}
}
-
- F Smoak
- October 12, 2020
- Like
- 0
- Continue reading or reply
after trigger not firing when record is created by custom apex and vf page
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!
-
- F Smoak
- October 07, 2020
- Like
- 0
- Continue reading or reply
Need to reduce query rows and CPU Time and debug log size for apex after insert trigger
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());
}
}
-
- F Smoak
- October 01, 2020
- Like
- 0
- Continue reading or reply
Trying to populate Map<Id,Set<String>> but cannot crack how to ensure no duplicate values of string are put in map.
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!
-
- F Smoak
- September 28, 2020
- Like
- 0
- Continue reading or reply
DML requires SObject or SObject list type: Set<String>
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;
}
-
- F Smoak
- September 28, 2020
- Like
- 0
- Continue reading or reply
fetch translated value of picklist field using apex
-
- F Smoak
- July 09, 2020
- Like
- 0
- Continue reading or reply
batch apex to combine all batch records processed to insert record
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());
}
}
}
-
- F Smoak
- October 29, 2019
- Like
- 0
- Continue reading or reply
custom label translation not working
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);
}
-
- F Smoak
- October 22, 2019
- Like
- 0
- Continue reading or reply
how to restrict visibility of text field rows of values based on user's accountshare on a single record
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
}
}
-
- F Smoak
- September 30, 2019
- Like
- 0
- Continue reading or reply
check if datetime field has reached past 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.
-
- F Smoak
- September 28, 2019
- Like
- 0
- Continue reading or reply
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
}
}
-
- F Smoak
- September 27, 2019
- Like
- 0
- Continue reading or reply
An unexpected error occurred. Please include this ErrorId if you contact support: 659496249-16238 (-910256754)
Kindly let me know how to fix this.
-
- F Smoak
- September 13, 2019
- Like
- 0
- Continue reading or reply
cannot retrieve user ids having specific territory names 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.
-
- F Smoak
- September 05, 2019
- Like
- 0
- Continue reading or reply
to get list of users under a territory and all it's child 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
-
- F Smoak
- September 05, 2019
- Like
- 0
- Continue reading or reply
Update Address as Account field value updates
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;
}
-
- F Smoak
- April 14, 2017
- Like
- 0
- Continue reading or reply
Trigger for inserting child obj field value in account.
Note: Product M -- this value is coming from lookup field from a different obj X.
-
- F Smoak
- December 26, 2016
- Like
- 0
- Continue reading or reply
Trying to populate Map<Id,Set<String>> but cannot crack how to ensure no duplicate values of string are put in map.
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!
- F Smoak
- September 28, 2020
- Like
- 0
- Continue reading or reply
DML requires SObject or SObject list type: Set<String>
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;
}
- F Smoak
- September 28, 2020
- Like
- 0
- Continue reading or reply
fetch translated value of picklist field using apex
- F Smoak
- July 09, 2020
- Like
- 0
- Continue reading or reply
check if datetime field has reached past 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.
- F Smoak
- September 28, 2019
- Like
- 0
- Continue reading or reply
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
}
}
- F Smoak
- September 27, 2019
- Like
- 0
- Continue reading or reply
An unexpected error occurred. Please include this ErrorId if you contact support: 659496249-16238 (-910256754)
Kindly let me know how to fix this.
- F Smoak
- September 13, 2019
- Like
- 0
- Continue reading or reply
cannot retrieve user ids having specific territory names 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.
- F Smoak
- September 05, 2019
- Like
- 0
- Continue reading or reply
what is Apex managed sharing? How its work and which case we can use?
Please clear my confussion..
Thanks in advance
- Muni12345
- November 29, 2016
- Like
- 0
- Continue reading or reply
SOQL Grouping and Ordering in same statement
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?
- SF_Rocks
- July 11, 2014
- Like
- 0
- Continue reading or reply
Aggregate queries and Batch Apex: just not meant to work together?
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
- dmcheng
- November 11, 2010
- Like
- 0
- Continue reading or reply
How can I access Custom Labels from Apex code classes?
- Jan4C
- September 30, 2008
- Like
- 0
- Continue reading or reply