• pranav_sanvatsarkar
  • NEWBIE
  • 74 Points
  • Member since 2018
  • Senior Salesforce Developer
  • Billennium


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 11
    Replies
Hi,

I am looking for help on how to impliment a certain piece of functionality to my org,

I have a field in my org which is a picklist, it contains various statuses - one of the statuses is 'resolved' 

I am looking to create a field and a respective workflow which, when the piclist field is changed to a certain status (resolved), the workflow triggers to show the user which changes the picklist to the respective value. 

Many thanks,
Sean
Hi all, 

I am trying to complete this Trailhead Challenge (https://trailhead.salesforce.com/content/learn/modules/asynchronous_apex/async_apex_batch) where it calls a static method (sendMessage(job, recordsPRocessed) from a utility class (EmailUtils).

I do not have this email utililty class anywhere in my org, and I am new to Apex coding so I don't know how to create one either. Does anyone happen to have this utility class which you would be kind enough to share with me please?

Sample Code is as follow, it is currently throwing an error ("Variable does not exist: EmailUtils)

Any help is greatly appreciated!

global class UpdateContactAddresses implements
    Database.Batchable<sObject>, Database.Stateful {
                global Integer recordsProcessed = 0;
        global Database.QueryLocator start(Database.BatchableContext bc){
            return Database.getQueryLocator(
                'SELECT ID, BillingSteet, BillingCity, BillingState, ' + 
                'BillingPostalCode, (SELECT ID, MailingStreet, MailingCity, ' + 
                'MailingState, MailingPostalCode FROM Contacts) FROM Account ' +
                'WHERE BillingCountry = \'USA\''
            );                
        }
        
        global void execute(Database.BatchableContext bc, List<Account> scope){
            List<Contact> contacts = new List<Contact>();
            for(Account account : scope) {
                for(Contact contact : account.contacts){
                    contact.MailingStreet = account.BillingStreet;
                    contact.MailingCity = account.BillingCity;
                    contact.MailingState = account.BillingState;
                    contact.MailingPostalCode = account.BillingPostalCode;
                    contacts.add(contact);
                    recordsProcessed = recordsProcessed + 1;
                }
            }
            update contacts;             
        }
        global void finish(Database.BatchableContext bc){
            System.debug(recordsProcessed + ' records processed. Shazam!');
            AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems,CreatedBy.Email FROM 
                               AsyncApexJob WHERE Id = :bc.getJobId()];
               EmailUtils.sendMessage(job,recordsProcessed);
        }

}
Hello there,

I am trying to use ConnectAPI to implement some custom chatter functionality in my developer edition org. However, while trying to save the following code, I am getting the error, "Variable does not exist: ConnectApi"

This is the code that I am trying to deploy in a non-static public method in an Apex class.
ConnectApi.ChatterGroupInput groupInput = ConnectApi.ChatterGroupInput();

I may be missing a very simple piece of prerequisite, however, not able to find the same on internet.

Thanks in advance!
Hello there,

I am trying to use ConnectAPI to implement some custom chatter functionality in my developer edition org. However, while trying to save the following code, I am getting the error, "Variable does not exist: ConnectApi"

This is the code that I am trying to deploy in a non-static public method in an Apex class.
ConnectApi.ChatterGroupInput groupInput = ConnectApi.ChatterGroupInput();

I may be missing a very simple piece of prerequisite, however, not able to find the same on internet.

Thanks in advance!
Hi All,
Need help with below test case

@isTest

private class TestTimecardManager{

@testSetup static void setup()
{
Contact conct = new contact(FirstName='Test', LastName='TestLastName', Phone='4565465789');

insert conct;

Project__c prj = new Project__c(Name ='MyProject');

insert prj;
}

@isTest static void TestInserMethodValid()
{

//code to access contact and project objects

Assignment__c assign = new Assignment__c(Contact__c=conct.Title,Project__c='MyProject',Start_Date__c=Date.parse('01/01/2019'),End_Date__c=Date.parse('10/01/2019'));

}
}


As you see I need to access the contact and project object in TestInserMethodValid() method.

Need your help!.
Hi ,

I Need some information about how to create a API for activity log in which leads is associated.

Thanks.
 

Hi, I have the following error: I'm not sure how to fix this

 When i ran the class i have one error which is this..
"SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, a3D9E000000Mdz0]—Send Email method looks for a contact while sending emails"

This is my code for sending email to users or queues

global class sendEmailBatchClass implements Database.Batchable < sobject > {
   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        Date dt = date.today().addDays(1);
        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) {
       
        String userStringVal = '005';
        Map<Id,set<SVMXC__Service_Request__c>> srMap = new Map<Id, set<SVMXC__Service_Request__c>>();
        Map<Id, Set<SVMXC__Service_Order__c>> woMap = new Map<Id, Set<SVMXC__Service_order__c>>();
        Map<Id, Set<SIG_Administrative_Task__c>> atMap = new Map<Id, Set<SIG_Administrative_Task__c>>();
        Map<String, set<SVMXC__Service_Request__c>> userSRMap = new Map< String, set<SVMXC__Service_Request__c>>();
        Map<String, set<SVMXC__Service_Order__c>> userWoMap = new Map< String, set<SVMXC__Service_Order__c>>();
        Map<String, set<SIG_Administrative_Task__c>> userATMap = new Map< String, set<SIG_Administrative_Task__c>>();
       
        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);
                }
            }
            else{
                if(!srMap.containsKey(srVal.OwnerId)){
                    srMap.put(srVal.OwnerId,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   srMap.get(srVal.OwnerId).add(srVal);
                }
            }
            
            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;
                email.setTargetObjectId(srlistval.ownerId);
                email.setWhatId(srlistval.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {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);
                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;
                email.setTargetObjectId(adListVal.ownerId);
                email.setWhatId(adListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          
          
    }
    
    global void finish(database.BatchableContext bc) {
        
    }
}
Hi,

I am looking for help on how to impliment a certain piece of functionality to my org,

I have a field in my org which is a picklist, it contains various statuses - one of the statuses is 'resolved' 

I am looking to create a field and a respective workflow which, when the piclist field is changed to a certain status (resolved), the workflow triggers to show the user which changes the picklist to the respective value. 

Many thanks,
Sean
Hi Guys,

I did try few workarounds but no luck so thought of posting to see if anyone has done it before, which I believe of course.

I have a custom Object B which as two Record types (1 and 2), Now I have added the Object B as a child (Related List) under Opportunities, but what I am looking is to display 2 related list views one of each Record Type under the same Opportunity Page Layout. 

Also to highlight, Opportunity and Object B has Master-Detail relationship.

Appreciate your key inputs.

Cheers,
Sachin
Hi,
I am trying to integrate Salesforce with some Git repository but I have no idea of what to use. Salesforce recommend to use Ant IT but I have seen a lot of Jenkins tutorials but nothing up to date. My idea is to work as a team and forget to commit our code to git, any ideas? Thank you in advance
Hi all,

I have class generated from WSDL file from SAP and when i am testing the generated class, I need to provide a fake response as Input.

can any one of u tell me how to provide input for a data type of "sapComDocumentSapSoapFunctionsMcSV.TableOfZcqppmscore".

I Mean exactly for kind of data can we give it as I/P.

for ex: string = 'this is string';
           integer = 20;

 
Hi all, 

I am trying to complete this Trailhead Challenge (https://trailhead.salesforce.com/content/learn/modules/asynchronous_apex/async_apex_batch) where it calls a static method (sendMessage(job, recordsPRocessed) from a utility class (EmailUtils).

I do not have this email utililty class anywhere in my org, and I am new to Apex coding so I don't know how to create one either. Does anyone happen to have this utility class which you would be kind enough to share with me please?

Sample Code is as follow, it is currently throwing an error ("Variable does not exist: EmailUtils)

Any help is greatly appreciated!

global class UpdateContactAddresses implements
    Database.Batchable<sObject>, Database.Stateful {
                global Integer recordsProcessed = 0;
        global Database.QueryLocator start(Database.BatchableContext bc){
            return Database.getQueryLocator(
                'SELECT ID, BillingSteet, BillingCity, BillingState, ' + 
                'BillingPostalCode, (SELECT ID, MailingStreet, MailingCity, ' + 
                'MailingState, MailingPostalCode FROM Contacts) FROM Account ' +
                'WHERE BillingCountry = \'USA\''
            );                
        }
        
        global void execute(Database.BatchableContext bc, List<Account> scope){
            List<Contact> contacts = new List<Contact>();
            for(Account account : scope) {
                for(Contact contact : account.contacts){
                    contact.MailingStreet = account.BillingStreet;
                    contact.MailingCity = account.BillingCity;
                    contact.MailingState = account.BillingState;
                    contact.MailingPostalCode = account.BillingPostalCode;
                    contacts.add(contact);
                    recordsProcessed = recordsProcessed + 1;
                }
            }
            update contacts;             
        }
        global void finish(Database.BatchableContext bc){
            System.debug(recordsProcessed + ' records processed. Shazam!');
            AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems,CreatedBy.Email FROM 
                               AsyncApexJob WHERE Id = :bc.getJobId()];
               EmailUtils.sendMessage(job,recordsProcessed);
        }

}
I wrote a batch apex that invokes a Flow interview. Somehow my Test class is not covering execute method. Can anyone help me out?
Batch Apex:
global class Lead_remind implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        Date d = Date.today();
        String query = 'SELECT Id, OwnerId, Reminder_date__c, Rev_Date__c, Status FROM Lead where Status=\'Qualify\' AND Reminder_date__c=:d';
  return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Lead> scope)
    {
        for(Lead l : scope)
        {
            Map<String, Object> params = new Map<String, Object>();
            params.put('LId',l.Id);
            params.put('LeadOwnerId',l.OwnerId);
            params.put('BusinessDay_3',l.Reminder_date__c);
            params.put('BusinessDay_4',l.Rev_Date__c);
            Flow.Interview.Lead_Flow lFlow = new Flow.Interview.Lead_Flow(params);
            lFlow.start();       
        }
        update scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }

}

Test Class:
 
@isTest
private class Lead_remind_Test {
static testMethod void testMethod1() 
    {
            Lead L= new Lead();
            L.OwnerId = '0055A00000A6s5pLAQ';
            L.LastName ='Lead Name';
            L.Company = 'Lead Company';
            L.Status = 'New'; 
            L.LeadSource = 'Social';
            L.Phone = '7364859473';
            insert L;
        
           L.Reminder_date__c = Date.today();
           L.Status = 'Qualify';
	   update L;
        
        Test.startTest();
            Lead_remind obj = new Lead_remind();
            DataBase.executeBatch(obj); 
        Test.stopTest();
    }
}

Reminder_date__c, Rev_Date__c are 'Date' fields. These fields will be populated by a workflow when Lead status is 'Qualify'.
  • November 01, 2018
  • Like
  • 0