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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 39
    Replies
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 have a custom object A and record types A1,A2,A3 
I want to write a before delete trigger and it's supporting test class so that it prevents deleting of A1 record type records but can delete A2,A3 record type records.
Please help!
I have created an email alert and I need to add disc bullet points to HTML Version of email template. I have added the below tags:
<ul type = "disc">
<li> item 1 </li>
</ul>

This is not working, please help me achieve disc bullets!
I have a Workflow which does field updates on creating a record for an object. I need to deactivate this W/F and use Process Builder which would do field updates and also locak the record preventing it to be deleted. I have replicated the W/F criterias but I cant seem to create field updates.
Can anyone please help?
 
I need to give access to a user to deleted records- I have provided Delete permission to profile on object permissions. When I am trying to delete the record it lets me delete one record type record but does not allow me to delete other record types by giving following error: 
nsufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. 

Click here to return to the previous page.

Please help!
I am trying to create a dashboard based on a report to show accounts spread accross different segements and territories. Now I want to give access to such a dashboard to an end user. Its throwing me below error in end user home page:
User-added image
TO resolve this I checked if it has object access and FLS for the objects used in report. I could checke all however I cannot confirm for Territory Object. Can anyone please help me on this, as I am new to Reports and Dashboards.

Thanks
Ruchi

I need to write a simple test class to display Account and child object( Address) related fields, how can I write such a class?
 

Thanks
Ruchi

I am creating a VF page for creating Business Account. I am stuck at below points:
--- I want to display Record Type field as read only on the form. How can I do so?
--- I want to display Address (child object for account) related info in the same page but its not helping using Account standard controller so what should be a class tag for the same so that I can display address related info as well?

Please help!

Thanks
Ruchi
I have created a report for a custom object. Now I want a user to have access to only specific record type on report. So I added a record type filter. When I run the report with the filter it shows no records but when I have not added any filter it shows all record. Due to security issue I need to give access only on specific record tyep. Please help!
I have a parent Object Person Account and related child object Address.
While creating an account I need to display some field of Address as required fields. How can I do that? 
On Address Layout assignment these fields are required but while creating account these fields do not mark as required. How to fix this? Please help!
I have created a new profile and it needs access to My Accounts tab. However when i navigate to My accounts it shows me few buttons in top of Accounts records view. I do not want to show some unwanted buttons to this new profile. How do I remove this?

Please help! Thank You in Advance :)
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