• harsha__c
  • SMARTIE
  • 1181 Points
  • Member since 2012

  • Chatter
    Feed
  • 40
    Best Answers
  • 0
    Likes Received
  • 6
    Likes Given
  • 4
    Questions
  • 288
    Replies
Hello,
I am actually writing a code that helps to get automatically the dependencies between Object.
While writing my code, I faced an issue. I cannot find a way to know when an object doesn't have a parent object.
How can I find that in apex ?
I am doing some development in my company's Sandbox environment. My work is not yet complete. The IT team plans to refresh the Sandbox today and I don't want to lose my work. I thought I might create a package, allow the refresh, and then install the package back into the Sandbox. But this is my first custom Salesforce development and I have not yet put any unit tests into my custom class and so I cannot upload my package. 

Is there a way around the unit test coverage requirement? Is there a better way to back up and restore my work around the Sandbox refresh? 

Hi, I wrote a batch class to send email notification to users from Queue. 
This is my class:

 

global class sendEmailBatchClass implements Database.Batchable < sobject > {
   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        Date dt = date.today().addDays(1);
        System.debug('scope ' + dt);
        return Database.getquerylocator([SELECT Id,OwnerId,Name,Owner.Email,
        (Select Id,OwnerId,Name,Owner.Email from SVMXC__Work_Orders__r where SIG_Due_Date__c =:dt and SVMXC__Order_Status__c NOT IN ('Closed','Completed')),
        (Select Id,OwnerId,Name,Owner.Email from Administrative_Tasks__r where SIG_Due_Date__c =:dt and SIG_Status__c Not IN ('Closed','Completed')) 
        From SVMXC__Service_Request__c  WHERE SVMXC__Status__c = 'Open' and SVMX_SIG_Due_Date__c  =: dt]);
    }
    
    global void execute(Database.BatchableContext bc, List <SVMXC__Service_Request__c> scope) {
       System.debug('scope ' + scope); 
        String userStringVal = '005';
        List<SVMXC__Service_Order__c> emailUsers = new List<SVMXC__Service_Order__c>();
        Map<Id,set<SVMXC__Service_Request__c>> srMap = new Map<Id, set<SVMXC__Service_Request__c>>();
        System.debug('#####srMap ' + srMap);
        Map<Id, Set<SVMXC__Service_Order__c>> woMap = new Map<Id, Set<SVMXC__Service_order__c>>();
        System.debug('#####woMap ' + woMap);
        Map<Id, Set<SIG_Administrative_Task__c>> atMap = new Map<Id, Set<SIG_Administrative_Task__c>>();
        System.debug('#####atMap ' + atMap);
        Map<String, set<SVMXC__Service_Request__c>> userSRMap = new Map< String, set<SVMXC__Service_Request__c>>();
        System.debug('#####userSRMap ' + userSRMap);
        Map<String, set<SVMXC__Service_Order__c>> userWoMap = new Map< String, set<SVMXC__Service_Order__c>>();
        System.debug('#####userWoMap ' + userWoMap);
        Map<String, set<SIG_Administrative_Task__c>> userATMap = new Map< String, set<SIG_Administrative_Task__c>>();
        System.debug('#####userATMap ' + userATMap);
        OrgWideEmailAddress[] owea = [select Id,DisplayName,Address from OrgWideEmailAddress where DisplayName = 'SIG OrgWideAddress'];

        For(SVMXC__Service_Request__c srVal:scope){
            If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userSRMap.containsKey(srVal.Owner.Email)){
                userSRMap.put(srVal.Owner.Email,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   userSRMap.get(srVal.Owner.Email).add(srVal);
                   system.debug('**userSRMap'+userSRMap);
                }                   system.debug('**userSRMap'+userSRMap);

            }
            else{
                if(!srMap.containsKey(srVal.OwnerId)){
                    srMap.put(srVal.OwnerId,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   srMap.get(srVal.OwnerId).add(srVal);
                   system.debug('***srMap'+srMap);
                }                   system.debug('**userSRMap'+userSRMap);

            }
            
            For(SVMXC__Service_Order__c woVal :srVal.SVMXC__Work_Orders__r){
                If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userWoMap.containsKey(woVal.Owner.Email)){
                userWoMap.put(woVal.Owner.Email,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   userWoMap.get(woVal.Owner.Email).add(woVal);
                }
            }
            else{
                if(!woMap.containsKey(woVal.OwnerId)){
                    woMap.put(woVal.OwnerId,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   woMap.get(woVal.OwnerId).add(woVal);
                }
            }
            }
            
            For(SIG_Administrative_Task__c atVal :srVal.Administrative_Tasks__r){
                If(string.valueOf(atVal.OwnerId).startsWith(userStringVal)){
                if(!userATMap.containsKey(atVal.Owner.Email)){
                userATMap.put(atVal.Owner.Email,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   userATMap.get(atVal.Owner.Email).add(atVal);
                }
            }
            else{
                if(!atMap.containsKey(atVal.OwnerId)){
                    atMap.put(atVal.OwnerId,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   atMap.get(atVal.OwnerId).add(atVal);
                }
            }
            }
         }
         /***  Group Member Extracting ***/
         
         Set<Id> groupIds = new Set<Id>();
         groupIds.addAll(srMap.keyset());
         groupIds.addAll(woMap.keyset());
         groupIds.addAll(atMap.keyset());
         Map<Id,Set<user>> GpMap = new Map<Id,Set<User>>();
         
         Map<Id,User> userVal = new Map<Id,User>([SELECT User.Id, User.Email FROM User WHERE Id IN 
                                                (SELECT UserOrGroupId FROM GroupMember WHERE GroupId in : groupIds)]);
         
         
         For(GroupMember gm :[Select groupId, UserOrGroupId From GroupMember where groupId IN : groupIds]){
             if(GpMap.containsKey(gm.groupId)){
                 GpMap.get(gm.groupId).add(userVal.get(gm.UserOrGroupId));
             }else{
                 GpMap.put(gm.groupId,new set<User>{userVal.get(gm.UserOrGroupId)});
             }
         }
         // Extracting group member from Service Request
         
         If(!GpMap.isEmpty() && !srMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                if(!userSRMap.containsKey(usVal.Email)){
                userSRMap.put(usVal.Email,new set<SVMXC__Service_Request__c>(srMap.get(gVal)));
                }
                else
                {
                   userSRMap.get(usVal.Email).addAll(srMap.get(gVal));
                }
              }
         }
         }
        
         
          // Extracting group member from Work Order
          
         If(!GpMap.isEmpty() && !woMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                 if(!userWoMap.containsKey(usVal.Email)){
                 userWoMap.put(usVal.Email,new set<SVMXC__Service_Order__c>(woMap.get(gVal)));
                }
                else
                {
                   userWoMap.get(usVal.Email).addAll(woMap.get(gVal));
                }
              }
         }
         }
          // Extracting group member from Service Request
          
          If(!GpMap.isEmpty() && !atMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                  
                if(!userSRMap.containsKey(usVal.Email)){
                userATMap.put(usVal.Email,new set<SIG_Administrative_Task__c>(atMap.get(gVal)));
                }
                else
                {
                   userATMap.get(usVal.Email).addAll(atMap.get(gVal));
                }
              }
         }
         }
         
         // Sending Email for Service Request
          For(String userval1: userSRMap.keyset()){
           For(SVMXC__Service_Request__c srlistval: userSRMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
               // email.setTargetObjectId(srlistval.ownerId);
               String[] toAddresses ;
                    
              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
                toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(srlistval.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
                                   system.debug('***email Message'+email);

            }
          }
          
          // Sending Email For Work Order
    
          For(String userval1: userWoMap.keyset()){
           For(SVMXC__Service_Order__c woListVal: userWoMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Work_Order_Escalation_Email'].id;
                //email.setTargetObjectId(woListVal.ownerId);
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
                String[] toAddresses ;
  
              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
              //  toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                 toAddresses = new String [] {};
                for (String emaill : emailUsers.SIG_Queue_Members_Email_Address__c.split(',')) {
                                    String trimmed = email.trim();
                                    if (trimmed.length() > 0) {
                                     
                                     toAddresses.add(trimmed);
                                    }
                                  
                             }
                       
                             
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(woListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
               Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Admin  Task
           For(String userval1: userATMap.keyset()){
           For(SIG_Administrative_Task__c adListVal: userATMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                // Create Contact
                    Contact con;
                    con = new Contact();
                    con.FirstName = 'Test';
                    con.LastName = 'Contact';
                    con.Email = 'no-reply@organization.com';
                    insert con;
                    email.setTargetObjectId(con.Id);
               // email.setTargetObjectId(adListVal.ownerId);
               
               String[] toAddresses ;

              // I have hardcoded my Id for testing , please update the logic to add the respective email addresses.
                toAddresses   = new String[] {'vivek.agrawal@servicemax.com'};
                
                email.setOrgWideEmailAddressId(owea[0].Id);
                email.setCcAddresses(toAddresses);

                email.setWhatId(adListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          
          
    }
    
    global void finish(database.BatchableContext bc) {
        
    }
}


I'm trying to loop through each user from the Queue but i'm not sure how to do it...Also I have this error, I think from here I can solve my problem
User-added image

Hi All,
How can i add dynamically picklist value when i am uploading file using data loader (when value is not there from csv that will add as picklist value).Is there any work around....
Hello,

how can I find out what the associated SOQL query is to a field in SFDC. For example if I want to know what the SOQL query for an account field named 'Account Name' is?
Hi,
I need to fetch my content of my document which is uplaoded to the attachment.
I need to pass the query in REST API through workbench
So far I tried , Select id,ContentDocumentId,ContentDocument.LatestPublishedVersionId from ContentDocumentLink where LinkedEntityId IN ('a011I00000D55nx') , This gives the result as url,
Anyone of them pleae let me know how to get the body of the file?
I receive a feed of employees I load into a custom object. It has the employee number from another system.

I need to be able to update another  LOOKUP field  (relationsjhip is the User table) based on the employee number the user enters.

The employee number is a field in the USER table  ..so I need to match on it and return the userID to the empty lookup field

Can this be done with a workflow or process builder.  

Example:

Text fied value  Employee Number = 50410 
Need to relate that value to the user.employeeID
and  return the user.ID to a seperate lookup field  
 
Hi All,

I have the above error when I setup a Data Mapping with Adobe Sign. The data mapping is trying to check a checkbox on Quote object, but the process builder that is causing the above error is not related to the checkbox on Quote.

Any idea why this error occurs? Any help would be greatly appreciated!!

Nav
when click on button whole page will be redirecting using through apex page reference method
will the changes we make to the custom settings objects be reflected to production
Hi All,

I am facing a issue in the tadorderhint/tabindex of inputcheck/inputField ?
After 58 taborder disappears ?? ( these are checkbox fields )
Also tried inputcheck and taborder but no luck..
The Tab order does not appear on checkbox ( highlighted below)
Any ideas ??

<apex:pageBlockSection  title="Required Prod" columns="1" >
<apex:pageBlockSection id="red5" title="Sales Turnover & Forecasts" columns="1" >
 <apex:inputField Label="What was value of your total sales?" value="{!demo__c.Turnover__c}" taborderhint="56"/>
 <apex:inputField Label="What is forecast for the next 12 months?" value="{!demo__c.Year_1_Turn_Over__c}" taborderhint="57"/> <apex:inputField Label="What is forecast for the next 12 To 24 months?" value="{!demo__c.Year_2_Turn_Over__c}" taborderhint="58"/>
</apex:pageblockSection>
<apex:pageBlockSection  title="Required Prod1" columns="1" >
  <apex:inputField value="{!demo__c.2_Credit__c}" taborderhint="59"/> 
 <apex:inputField value="{!demo__c.1_Credit__c}" taborderhint="60"/>
<apex:inputField value="{!demo__c.3_Credit__c}" taborderhint="61"/>
<apex:inputField value="{!demo__c.4_Credit__c}" taborderhint="62"/>
<apex:inputField value="{!demo__c.Option4__c}" taborderhint="63"/>

</apex:pageblockSection>
Good Morning,
A prior Admin in my org set up a job to delete records when a new import occurs in a custom object on a daily basis.
To explain, we use a custom object in our org called "Additional Related Contacts". It imports from our core banking system and attaches to our contacts object. It is supposed to delete the old and replace with the new. It appears to be not functioning and I have no idea where to even look for this job.
I've looked in scheduled Jobs, Apex Jobs, Background Jobs, Bulk data Load etc and nothing appears to be what I am looking for.
How would I go about uncovering this needle in the haystack.
Any ideas or suggestions are appreciated.

 
Hi All

How to overcome salesforce limitation System.LimitException: Too many SOQL queries: 101

 
List<MasterCopy__c> masterCopyList = new List<MasterCopy__c>([Select Name,DateUpdate__c, Opening_Balance__c, Closing_Balance__c, Master_Code__c, Master_Name__c from MasterCopy__c]);
    List<MasterCopy__c> upsertMasterList = new List<MasterCopy__c>();
    MasterCopy__c masterCopyInsert;
    List<MasterTest__c> masterTestList = new List<MasterTest__c>([Select Date__c, Opening_Balance__c, Master_Code__c, Name, Closing_Balance__c from MasterTest__c]);
    if(trigger.isBefore && trigger.isInsert  ){
        for(MasterTest__c masterTest : trigger.new){
            masterTest.EntryDate__c = masterTest.Date__c;
            masterTest.To_Date__c = masterTest.Date__c;
            masterTest.From_Date__c = masterTest.Date__c;
            
            
            masterTest.Closing_Balance__c = masterTest.Opening_Balance__c;
        }
    }

 

Hi

 

I wrote a visualforce page and what I thought was a cool chunk of javascript which, when executed, copies values in the page from some inputfields to others (without updating the record—user can still save or cancel). It works fine except in the case of two fields which are a controller/dependent picklist pair. Boiled right down, the problem code is here:

 

document.getElementById(DestContPListID).value = document.getElementById(SourceContPListID).value;
document.getElementById(DestDepdPListID).value = document.getElementById(SourceDepdPListID).value;

 

The first line populates the controller picklist correctly but despite the second line the dependent picklist does not gain a value (most of the time). The reason seems to be that after I set the Controller picklist value (eg Tea) the dependent picklist does not show the possible values (eg English Breakfast, Earl Grey, Oolong, etc) and even when the code attempts to set it to one of these allowed values the field remains blank.

 

Note, I have tried manually setting the Controller Picklist to the desired value first (ie Tea) and then the dependent displays the possible values. If I run the script afterwards, it works fine. I assume I need something like this:

 

document.getElementById(DestContPListID).value = document.getElementById(SourceContPListID).value;
document.getElementById(SourceContPListID).systemMethodWhichKicksTheStandardControllerIntoActionToUpdateElementsOnPage;
...

 Or may be not. 

 

BTW, I am using "pure" javascript. Haven't venture into using the AJAX Toolkit yet but willing to try if it is the solution here.

 

Thanks for any help.

 

Regards

MellowRen