• Sunny S
  • NEWBIE
  • 45 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 19
    Replies
Hello dear community!!
Hoping somebody could help me with the below Test Class error.
 
I have a @isTest class which is failing the 'Run Test' throwing the following error message: 'System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.'
 
Apparently the Code Coverage is coming as 100%
 
I've referenced the following Salesforce article : https://help.salesforce.com/s/articleView?id=000330685&type=1
 
Test Class Code: 
 
@isTest private class MilestoneTest {         static testMethod void TestCompleteMilestoneCase(){         Set<String> milestoneNames = new Set<String>{'Resolution Time','Waiting for Customer','Change of Status'};         List<Account> acts = new List<Account>();         Account myAcc = new Account(Name='TestAct', phone='1001231234');         acts.add(myAcc);                  Account busAcc = new Account(Name = 'TestForMS', phone='4567890999');         acts.add(busAcc);         insert acts;         Contact cont = new Contact(FirstName = 'Test', LastName = 'LastName', phone='4567890999', accountid = busAcc.id);         insert(cont);                  Id contactId = cont.Id;         Entitlement entl = new Entitlement();         List<SlaProcess> lstEntitlementProcess = [SELECT Id, Name FROM SlaProcess WHERE IsActive = true limit 1];         if (lstEntitlementProcess.size()>0){             entl = new Entitlement(Name='Customer Feedback SLA',SlaProcessId= lstEntitlementProcess[0].id,AccountId=busAcc.Id,type='Change of Status',                                     StartDate=Date.valueof(System.now().addDays(-2)), EndDate=Date.valueof(System.now().addYears(2)));             insert entl;         }                 String entlId;         if (entl != null)             entlId = entl.Id;          List<Case> cases = new List<Case>{};             if (entlId != null){                 Case c = new Case(Subject = 'Test Case with Entitlement ', Priority='High',                                   EntitlementId = entlId, ContactId = contactId,slaStartDate=system.now());                 cases.add(c);             }         if(cases.isEmpty()==false){             insert cases;             List<Id> caseIds = new List<Id>();             for (Case cL : cases){                 caseIds.add(cL.Id);             }             Test.startTest();             milestoneUtils.completeMilestone(caseIds, milestoneNames, System.now());             Test.stopTest();         }     } }
 
*******#####*********
 
FYI - There is a Batch Class in the system which is running for a different installed Application.
 
Help: Could somebody suggest me the changes that I should be making to this Test Class in order to make it run successfully ?
 
Thanks in advance!!
Hi friends, 
I am pretty new to Apex and coming across the following error 'Error: Compile Error: Unexpected token 'global'. at line 7 column 13' whlie trying to save a code to Delete records from a Custom Object called Bookings

I had tried my best but still failing to get over the error.
Can someone please help me in resolving it? I had copied this code from one of Salesforce KB's. 

Use Case: We are looking to call this Class from a scheduled Flow on specific days in order to delete records, as we are short of storage in one of the Sandboxes.

Additionally - how can i add more than ONE object within the same code? so that the deletion operation can work on both objects?

Thanks in advance and any help will be greatly appreciated.

Regards,
Sunny


************ Code Starts Here ********************

global class BookingBatchDeletion implements Database.Batchable<sObject>, Schedulable 
{   
    global BookingBatchDeletion()
    {
            global final String Query;    
    
            global BookingBatchDeletion (String q) {
            Query = q;
            
           //constuctor  
    }
                
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        // query to delete Booking records
       
        return Database.getQueryLocator(delete[SELECT id FROM Booking__c LIMIT 10000];);
    } 
    
    global void execute(SchedulableContext sc)  
    {   
        //execute the batch
        BookingBatchDeletion deleteCS = new
BookingBatchDeletion();
        ID batchprocessid = Database.executeBatch(deleteCS);
    }
    
    global void execute(Database.BatchableContext BC, list<Booking__c> scope)
    {     
      System.debug('## deleting '+scope.size()+' booking records');   
 
        //delete list of Booking records
            delete scope;   
            Database.emptyRecycleBin(scope);  
    }
        
    global void finish(Database.BatchableContext BC) 
    {                 
        //no post processing
       
     }
}

********* Code Ends Here ***************
Hi all, 
I am still very new to Integration and API's, hence seek your help with the below query, please!

Q: We are looking to create Cases using REST Api, and got successfull in creating test cases uisng Post in Postman. 

User-added image

Problem: How do we populate the Contact Email and Contact Name for existing Contacts creating Tickets, so that Cases gets attached to the Conatct ?

Many thanks in advance!
Hello friends, need suggestion please.
I have inherited a trigger written by my predecessor which is throwing exception error. Can someone help in getting this sorted? What is the reason of getting this error ?

****** Code Start ******
trigger OnAccountTrigger on Account (before update, before insert) {
    // Create the map to store mappings
    //Map<String, String> objParentAccountMapping = new Map<String, String>();
    // Create set to store ids
    Set<Id> arParentAccountIds = new Set<Id>();
    // get all the Ids for the accounts that are inserted in that execution context.
    for(Account objAccount : Trigger.New) {
        // Check if we have a person
        if ((objAccount.Person_Account_Parent__c != null) && (objAccount.IsPersonAccount)) {
            // Retrieve the related contact
            // Retrieve the parent account from objAccount.Person_Account_Parent__c
            // Update the local contact from the objAccount.PersonContactId of that retrieved parent
            arParentAccountIds.add(objAccount.Person_Account_Parent__c);
        }
    }
   
    // Store the map   
    Map<Id, Account> objAccountChildContact = new Map<Id, Account>([select Id, PersonContactId from Account WHERE Id IN : arParentAccountIds]);
   
    System.debug('Map');
    System.debug(objAccountChildContact);

    // get all the Ids for the accounts that are inserted in that execution context.
    for(Account objAccount : Trigger.New) {
        // Check if we have a person
        if ((objAccount.Person_Account_Parent__c != null)) {
            // Retrieve the related contact
            // Retrieve the parent account from objAccount.Person_Account_Parent__c
            // Update the local contact from the objAccount.PersonContactId of that retrieved parent

            // Set the contact
           /*below in red is line 32*/
 objAccount.Parent__pc = objAccountChildContact.get(objAccount.Person_Account_Parent__c).PersonContactId; 
            System.debug('Updating contact parent for [' + objAccount.Id + '] to [' + objAccount.Parent__pc +']');
           
        }
    }
}


Error Message:
Apex script unhandled trigger exception by user/organization:
OnAccountTrigger: execution of BeforeUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.OnAccountTrigger: line 32, column 1

***** Code End *****

Thanks in advance !


 
Hi community friends, need some help please !

Overview:
We are getting some Person Accounts to flow into SalesCloud from one of the external systems (Dynamics 365).

We are than using Process Builder to auto create “Leads” for these accounts (for reporting and marketing perspective) – PB seems to be working correctly fine here;

Requirement:
1: We want to automate these Leads (just these ones) to close as  ‘Converted’ upon creation; plus if possible

2: Have the opportunities to get auto created and close as ‘Closed – Won’ upon creation  – without creating an account (as the account already exists)

I am been trying to use a combination of the following Apex class and Trigger, but seems is not working as desired…. Would anyone be able to help me with this issue please ?

Apex Trigger:
Trigger AutoConvertLead on Lead(After Insert)
{
   For(Lead ld : trigger.new){
        //  calling apex class method to convert this lead
  AutoConvertLead.leadconversion(ld.id)
 }
    }

Apex Class:
Public class AutoConvertLead(){
     public static void leadConversion(string leadid){
        Database.LeadConvert Leadconvert = new Database.LeadConvert();
           // pass the leadId which need to be converted
        Leadconvert.setLeadId(leadid);
   LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
       Leadconvert.setConvertedStatus(convertStatus.MasterLabel);
        Leadconvert.setCreateOpportunity(True);
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.assert(Leadconverts.isSuccess());
}
}


Thanks and regards,
Sunny


 
Hi dear members, need some advice please!

We are sending out a survey to our customers through Marketing Cloud system. (survey was itself created in SFMC)
Once a customer submits a survey, response gets recorded in SalesCloud Survey object 'Survey_Submission__c'. An auto Email then goes out to these customer from SalesCloud containing the same 'Survey URL' allowing them to change their responses if they wish to do so. 
Below is the Visualforce email template that we are using.

Issuse: How can i pass the customer name / Custome ID within this email template, so that if a customer clicks on the survey url, the system recognises the contact and makes the changes for that specific record in SalesCloud.


<messaging:emailTemplate subject="Survey Submission Email Notification : {!recipient.Firstname} {!recipient.Lastname}" recipientType="Contact" relatedToType="Survey_Submission__c">
<messaging:htmlEmailBody >

<img src= "https://companyname--uat--c.cs104.content.force.com/servlet/servlet.ImageServer?id=015200000HS2h&oid=00DN00008qOQ&lastMod=15827213900"/> <br/> <br/> <br/>

<p style="color:#2325C5">
Dear <b>{!recipient.Firstname} {!recipient.Lastname}</b>, <br/> <br/>

Congratulations, you have successfully submitted your survey
Please click on the below URL if you wish to change any of your survey responses.

<a href="https://www.survey_url_would_be_added_here.com/331578514d47s.pub.s.10.sfmc.content.com/i34gdhup?" > SURVEY_ID= "{!Survey_Submission__c.ContactId__c}" Change your submission here </a>

Regards, <br/>
Team XYZ
</p>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Kind regards!
Hi members, need help !

I am trying to create a Trigger (on Lead object) for Email Alert based on the Username. In the sense-  whenever a user deletes a lead record, an email should go out the the manager.... but getting across the below error. 
Can someone please rectify my Trigger and suggest that wrong am i doing here ?

*** TRIGGER***

trigger EmailAfterDeleteLead on Lead(after delete) {
    Messaging.reserveSingleEmailCapacity(trigger.size);
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            for (Lead lead : Trigger.old) { 
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                    if (userInfo.LastName=='Event Catering' && userInfo.LastName=='General Catering'){
                        email.setToAddresses(new String[] {'Manager@Functions.com'});
                        }
                        Else {
                    email.setToAddresses(new String[] {'Administrator@Functions.com'});
                email.setSubject('Deleted Lead Alert');
            email.setPlainTextBody('Dear Manager,' +'\n'+ 'This message is an alert that the following lead has been deleted from Salesforce by *** ' + UserInfo.getFirstName() + ' ' + UserInfo.getLastName() + '***. You can restore the deleted lead from recycle bin within 15 days ' + '\n \n'
        + 'Lead Name: ' + lead.FirstName + ' ' + lead.LastName + '\n'
        + 'Lead Email: ' + lead.Email + '\n'
        + 'Lead Status: ' + lead.Status + '\n'       
        + 'Lead Id: ' + lead.Id + '\n\n'
        + 'Current Salesforce User Name: ' + UserInfo.getFirstName() + ' ' + UserInfo.getLastName() +  '\n\n\n\n\n'
        );
        emails.add(email);
        }
        
    }
    Messaging.sendEmail(emails);

}

============================

User-added image
Hi Members, need help !

We have 3 objects as : 1- Event , 2- Invite and 3- Contacts (standard). 'Invite' is the Junction object between 'Event' and 'Contacts'.

Once and Event is created, we need to send out the Invites to our customer. For that we are building a Visualforce Page on 'Invite' object in order to capture this VFP inside the Invitation email.

Requiremrnt 1: How can we include a VFP inside a Visualforve Email template?
Requiremrnt 2: How can we send multiple Invites for an Event with a Single email, single click?
Requiremrnt 3: Is it possible to capture the customer response as 'Yes, No' directly onto the Invite object (for the particular event) on the basis of their input on the attached Visualforce page (inside the email)

Its like: An Event is created, an Invite email goes out to the customers, customer replies on the Invite email as: Yes, No and the response gets recorded against the respective event for that customer?

My visual page is also throwing an error !!

I am falling short of ideas here. Any help would be greatly appreciated... Thanks !

User-added image

 
Hi friends, need very very urgent help please !

Requirement: 
Is there a way to automate email notification alert to get triggered for user who have not logged in for past 20 days?

Basically, an email should automatically get fired to notify users about being not logging in for XYZ days.

I tried working with WFR and PB but failed to get over, as there won't be any action on these user accounts to trigger the automation.

I am sure that this could be acheived using Apex, but my lack of experince with coding is the biggest hurdle. 

Can anyone please please help me in getting this sorted step by step please, as this has come up as a very urgent piece of work, and failing to do this could get me fired.

Thanks in advance !
Hi all,
Need help. I am still a novice with Development, hence would need someone to please help me with the below query.

Background: We are having a custom object as 'Survey', which is having around 10-12 fields (combination of Text and picklist field).

Use of the Object: The fields in this object 'Survey' are getting populated dynamically - through AMP Script from Marketing Cloud. As these surveys are sent to customers through Marketing Cloud emails, and whatever input the customer add on the Survey Cloud Page, it automatically gets recorded under same name fields in Sales Cloud object.

Requirement: We want to send an 'Email Notification' to the Manager, each time a survey gets recorded in the Sales Cloud Object 'Survey' object.
Also, the Notification Email should display the 'Customer Name' 'Email' &  'Answers to all the questions of the Survey'.

I am not too sure how to achieve this using Apex and Trigger ?
Can someone please help me with this and explain the steps in basic language.

Thanks in advance !
Hello dear community!!
Hoping somebody could help me with the below Test Class error.
 
I have a @isTest class which is failing the 'Run Test' throwing the following error message: 'System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.'
 
Apparently the Code Coverage is coming as 100%
 
I've referenced the following Salesforce article : https://help.salesforce.com/s/articleView?id=000330685&type=1
 
Test Class Code: 
 
@isTest private class MilestoneTest {         static testMethod void TestCompleteMilestoneCase(){         Set<String> milestoneNames = new Set<String>{'Resolution Time','Waiting for Customer','Change of Status'};         List<Account> acts = new List<Account>();         Account myAcc = new Account(Name='TestAct', phone='1001231234');         acts.add(myAcc);                  Account busAcc = new Account(Name = 'TestForMS', phone='4567890999');         acts.add(busAcc);         insert acts;         Contact cont = new Contact(FirstName = 'Test', LastName = 'LastName', phone='4567890999', accountid = busAcc.id);         insert(cont);                  Id contactId = cont.Id;         Entitlement entl = new Entitlement();         List<SlaProcess> lstEntitlementProcess = [SELECT Id, Name FROM SlaProcess WHERE IsActive = true limit 1];         if (lstEntitlementProcess.size()>0){             entl = new Entitlement(Name='Customer Feedback SLA',SlaProcessId= lstEntitlementProcess[0].id,AccountId=busAcc.Id,type='Change of Status',                                     StartDate=Date.valueof(System.now().addDays(-2)), EndDate=Date.valueof(System.now().addYears(2)));             insert entl;         }                 String entlId;         if (entl != null)             entlId = entl.Id;          List<Case> cases = new List<Case>{};             if (entlId != null){                 Case c = new Case(Subject = 'Test Case with Entitlement ', Priority='High',                                   EntitlementId = entlId, ContactId = contactId,slaStartDate=system.now());                 cases.add(c);             }         if(cases.isEmpty()==false){             insert cases;             List<Id> caseIds = new List<Id>();             for (Case cL : cases){                 caseIds.add(cL.Id);             }             Test.startTest();             milestoneUtils.completeMilestone(caseIds, milestoneNames, System.now());             Test.stopTest();         }     } }
 
*******#####*********
 
FYI - There is a Batch Class in the system which is running for a different installed Application.
 
Help: Could somebody suggest me the changes that I should be making to this Test Class in order to make it run successfully ?
 
Thanks in advance!!
Hi all, 
I am still very new to Integration and API's, hence seek your help with the below query, please!

Q: We are looking to create Cases using REST Api, and got successfull in creating test cases uisng Post in Postman. 

User-added image

Problem: How do we populate the Contact Email and Contact Name for existing Contacts creating Tickets, so that Cases gets attached to the Conatct ?

Many thanks in advance!
Hello friends, need suggestion please.
I have inherited a trigger written by my predecessor which is throwing exception error. Can someone help in getting this sorted? What is the reason of getting this error ?

****** Code Start ******
trigger OnAccountTrigger on Account (before update, before insert) {
    // Create the map to store mappings
    //Map<String, String> objParentAccountMapping = new Map<String, String>();
    // Create set to store ids
    Set<Id> arParentAccountIds = new Set<Id>();
    // get all the Ids for the accounts that are inserted in that execution context.
    for(Account objAccount : Trigger.New) {
        // Check if we have a person
        if ((objAccount.Person_Account_Parent__c != null) && (objAccount.IsPersonAccount)) {
            // Retrieve the related contact
            // Retrieve the parent account from objAccount.Person_Account_Parent__c
            // Update the local contact from the objAccount.PersonContactId of that retrieved parent
            arParentAccountIds.add(objAccount.Person_Account_Parent__c);
        }
    }
   
    // Store the map   
    Map<Id, Account> objAccountChildContact = new Map<Id, Account>([select Id, PersonContactId from Account WHERE Id IN : arParentAccountIds]);
   
    System.debug('Map');
    System.debug(objAccountChildContact);

    // get all the Ids for the accounts that are inserted in that execution context.
    for(Account objAccount : Trigger.New) {
        // Check if we have a person
        if ((objAccount.Person_Account_Parent__c != null)) {
            // Retrieve the related contact
            // Retrieve the parent account from objAccount.Person_Account_Parent__c
            // Update the local contact from the objAccount.PersonContactId of that retrieved parent

            // Set the contact
           /*below in red is line 32*/
 objAccount.Parent__pc = objAccountChildContact.get(objAccount.Person_Account_Parent__c).PersonContactId; 
            System.debug('Updating contact parent for [' + objAccount.Id + '] to [' + objAccount.Parent__pc +']');
           
        }
    }
}


Error Message:
Apex script unhandled trigger exception by user/organization:
OnAccountTrigger: execution of BeforeUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.OnAccountTrigger: line 32, column 1

***** Code End *****

Thanks in advance !


 
Hi community friends, need some help please !

Overview:
We are getting some Person Accounts to flow into SalesCloud from one of the external systems (Dynamics 365).

We are than using Process Builder to auto create “Leads” for these accounts (for reporting and marketing perspective) – PB seems to be working correctly fine here;

Requirement:
1: We want to automate these Leads (just these ones) to close as  ‘Converted’ upon creation; plus if possible

2: Have the opportunities to get auto created and close as ‘Closed – Won’ upon creation  – without creating an account (as the account already exists)

I am been trying to use a combination of the following Apex class and Trigger, but seems is not working as desired…. Would anyone be able to help me with this issue please ?

Apex Trigger:
Trigger AutoConvertLead on Lead(After Insert)
{
   For(Lead ld : trigger.new){
        //  calling apex class method to convert this lead
  AutoConvertLead.leadconversion(ld.id)
 }
    }

Apex Class:
Public class AutoConvertLead(){
     public static void leadConversion(string leadid){
        Database.LeadConvert Leadconvert = new Database.LeadConvert();
           // pass the leadId which need to be converted
        Leadconvert.setLeadId(leadid);
   LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
       Leadconvert.setConvertedStatus(convertStatus.MasterLabel);
        Leadconvert.setCreateOpportunity(True);
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.assert(Leadconverts.isSuccess());
}
}


Thanks and regards,
Sunny


 
Hi members, need help !

I am trying to create a Trigger (on Lead object) for Email Alert based on the Username. In the sense-  whenever a user deletes a lead record, an email should go out the the manager.... but getting across the below error. 
Can someone please rectify my Trigger and suggest that wrong am i doing here ?

*** TRIGGER***

trigger EmailAfterDeleteLead on Lead(after delete) {
    Messaging.reserveSingleEmailCapacity(trigger.size);
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            for (Lead lead : Trigger.old) { 
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                    if (userInfo.LastName=='Event Catering' && userInfo.LastName=='General Catering'){
                        email.setToAddresses(new String[] {'Manager@Functions.com'});
                        }
                        Else {
                    email.setToAddresses(new String[] {'Administrator@Functions.com'});
                email.setSubject('Deleted Lead Alert');
            email.setPlainTextBody('Dear Manager,' +'\n'+ 'This message is an alert that the following lead has been deleted from Salesforce by *** ' + UserInfo.getFirstName() + ' ' + UserInfo.getLastName() + '***. You can restore the deleted lead from recycle bin within 15 days ' + '\n \n'
        + 'Lead Name: ' + lead.FirstName + ' ' + lead.LastName + '\n'
        + 'Lead Email: ' + lead.Email + '\n'
        + 'Lead Status: ' + lead.Status + '\n'       
        + 'Lead Id: ' + lead.Id + '\n\n'
        + 'Current Salesforce User Name: ' + UserInfo.getFirstName() + ' ' + UserInfo.getLastName() +  '\n\n\n\n\n'
        );
        emails.add(email);
        }
        
    }
    Messaging.sendEmail(emails);

}

============================

User-added image
Hi friends, need very very urgent help please !

Requirement: 
Is there a way to automate email notification alert to get triggered for user who have not logged in for past 20 days?

Basically, an email should automatically get fired to notify users about being not logging in for XYZ days.

I tried working with WFR and PB but failed to get over, as there won't be any action on these user accounts to trigger the automation.

I am sure that this could be acheived using Apex, but my lack of experince with coding is the biggest hurdle. 

Can anyone please please help me in getting this sorted step by step please, as this has come up as a very urgent piece of work, and failing to do this could get me fired.

Thanks in advance !
Hi all,
Need help. I am still a novice with Development, hence would need someone to please help me with the below query.

Background: We are having a custom object as 'Survey', which is having around 10-12 fields (combination of Text and picklist field).

Use of the Object: The fields in this object 'Survey' are getting populated dynamically - through AMP Script from Marketing Cloud. As these surveys are sent to customers through Marketing Cloud emails, and whatever input the customer add on the Survey Cloud Page, it automatically gets recorded under same name fields in Sales Cloud object.

Requirement: We want to send an 'Email Notification' to the Manager, each time a survey gets recorded in the Sales Cloud Object 'Survey' object.
Also, the Notification Email should display the 'Customer Name' 'Email' &  'Answers to all the questions of the Survey'.

I am not too sure how to achieve this using Apex and Trigger ?
Can someone please help me with this and explain the steps in basic language.

Thanks in advance !