You need to sign in to do that
Don't have an account?

"Looks like something went wrong, please try again later." while trying to Check Challenge on Superbadge unit
I try to check 3. challenge in User Authentication Setting Superbadge Unit and receive an error:
https://trailhead.salesforce.com/content/learn/superbadges/superbadge-user-authentication-settings

Custom Metadata Type Records Mass Insert Issues
Sfdx force:cmdt:record:insert --filepath /Desktop/test.csv --typename test__mdt --inputdir /Documents/main/default/objects --outputdir /Users/4530206/Documents/main/default/customMetadata
test_mdt has two fields: "text__c" and "num__c"
test.csv has three columns: "Name", "text__c", "num__c"




https://salesforce.stackexchange.com/questions/328317/unable-to-insert-custom-metadata-records-with-cmdt-command
https://help.salesforce.com/s/articleView?id=sf.custommetadatatypes_cli.htm&type=5
Also I found some known issue around Metadata Relationship below.
https://github.com/forcedotcom/cli/issues/544
Please mark as Best Answer if above information was helpful.
Thanks,

Hi Team Help me to resolve this
Lead Status (Open - Not Contacted)
If the lead is still in the same condition (Open - Not Contacted) after 4 hours of lead creation, an email has to be sent to the owner of the lead and the manager of the owner in CC.
The below code works for sending emails to lead owner if he is an individual owner (sending Cc mail to Manager), same like that if lead owner is queue it is sending only to user mail not user's Cc manager.
should now send emails to individual owners, CC their managers, and all users in queues, including the CC to queue user managers.
Plz Provide solution.
public class LeadClass implements Database.Batchable<SObject> { // Start method for the batch job public Database.QueryLocator start(Database.BatchableContext context) { // Calculate the datetime four hours ago DateTime fourHoursAgo = DateTime.now().addHours(-4); // Retrieve the leads that meet the criteria return Database.getQueryLocator([ SELECT Id, OwnerId, Owner.Email, Owner.Type, CreatedDate FROM Lead WHERE Status = 'Open - Not Contacted' AND CreatedDate >= :fourHoursAgo ]); } // Execute method for processing the batch public void execute(Database.BatchableContext context, List<Lead> scope) { // Create a map to store email messages Map<Id, Messaging.SingleEmailMessage> emailMap = new Map<Id, Messaging.SingleEmailMessage>(); // Create a set to store owner IDs Set<Id> ownerIds = new Set<Id>(); // Create a set to store queue IDs Set<Id> queueIds = new Set<Id>(); // Iterate over the leads in the current batch for (Lead lead : scope) { if (lead.Owner.Type == 'User') { // Add the lead's owner ID to the set of owner IDs ownerIds.add(lead.OwnerId); } else if (lead.Owner.Type == 'Queue') { // Add the lead's owner ID to the set of queue IDs queueIds.add(lead.OwnerId); } } // Query the owners and their details using the owner IDs Map<Id, User> ownerMap = new Map<Id, User>([ SELECT Id, Name, Email, ManagerId FROM User WHERE Id IN :ownerIds ]); // Create a set to store manager IDs Set<Id> managerIds = new Set<Id>(); // Iterate over the owner records to collect manager IDs for (User owner : ownerMap.values()) { if (owner.ManagerId != null) { // Add the owner's manager ID to the set of manager IDs managerIds.add(owner.ManagerId); } } // Query the managers and their details using the manager IDs Map<Id, User> managerMap = new Map<Id, User>([ SELECT Id, Name, Email FROM User WHERE Id IN :managerIds ]); // Iterate over the leads in the current batch for (Lead lead : scope) { if (lead.Owner.Type == 'User') { // Retrieve the lead's owner from the ownerMap User owner = ownerMap.get(lead.OwnerId); // Create an email message Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Set the recipient (owner's email address) email.setToAddresses(new List<String>{ owner.Email }); // Add owner's manager's email to cc recipients if available if (owner.ManagerId != null && managerMap.containsKey(owner.ManagerId)) { User manager = managerMap.get(owner.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { email.setCcAddresses(new List<String>{ manager.Email }); } } // Set the email subject and body email.setSubject('Lead Still not actioned upon'); email.setPlainTextBody('Dear ' + owner.Name + ',\n\n' + 'This is a notification regarding the lead with the status "Open - Not Contacted" that was created within the last 4 hours.\n\n' + 'Lead Record: ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + lead.Id + '\n\n' + 'Thank you.\n\n' + 'Best Regards,\n' + 'Your Company'); // Add the email message to the map using the lead's owner ID as the key emailMap.put(lead.OwnerId, email); } else if (lead.Owner.Type == 'Queue') { // Retrieve the queue users associated with the lead's queue List<User> queueUsers = [SELECT Id, Name, Email, ManagerId FROM User WHERE Id IN (SELECT UserOrGroupId FROM GroupMember WHERE GroupId = :lead.OwnerId)]; // Iterate over the queue users for (User queueUser : queueUsers) { // Create an email message Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Set the recipient (queue user's email address) email.setToAddresses(new List<String>{ queueUser.Email }); // Add queue user's manager's email to cc recipients if available if (queueUser.ManagerId != null && managerMap.containsKey(queueUser.ManagerId)) { User manager = managerMap.get(queueUser.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { email.setCcAddresses(new List<String>{ manager.Email }); } } // Set the email subject and body email.setSubject('Lead Still not actioned upon'); email.setPlainTextBody('Dear ' + queueUser.Name + ',\n\n' + 'This is a notification regarding the lead with the status "Open - Not Contacted" that was created within the last 4 hours.\n\n' + 'Lead Record: ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + lead.Id + '\n\n' + 'Thank you.\n\n' + 'Best Regards,\n' + 'Your Company'); // Add the email message to the map using the queue user's ID as the key emailMap.put(queueUser.Id, email); // CC the manager of the queue user if available if (queueUser.ManagerId != null && managerMap.containsKey(queueUser.ManagerId)) { User manager = managerMap.get(queueUser.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { emailMap.get(queueUser.Id).setCcAddresses(new List<String>{ manager.Email }); } } } } } // Send the email messages Messaging.sendEmail(emailMap.values()); } // Finish method for post-processing after the batch job finishes public void finish(Database.BatchableContext context) { // Do any post-processing after the batch job finishes } }


I have made changes to your code, tried simplifying it, and followed the best practice.
In your code, there is SOQL in the loop which is against the best practice. I have commented on the code
Here is the code
public class LeadClass implements Database.Batchable<SObject> { // Start method for the batch job public Database.QueryLocator start(Database.BatchableContext context) { // Calculate the datetime four hours ago DateTime fourHoursAgo = DateTime.now().addHours(-4); // Retrieve the leads that meet the criteria return Database.getQueryLocator([ SELECT Id, OwnerId, Owner.Email, Owner.Type, CreatedDate FROM Lead WHERE Status = 'Open - Not Contacted' AND CreatedDate >= :fourHoursAgo ]); } // Execute method for processing the batch public void execute(Database.BatchableContext context, List<Lead> scope) { // Create a map to store email messages Map<Id, Messaging.SingleEmailMessage> emailMap = new Map<Id, Messaging.SingleEmailMessage>(); // Create a set to store owner IDs Set<Id> ownerIds = new Set<Id>(); // Create a set to store queue IDs Set<Id> queueIds = new Set<Id>(); // Create a map to store List of Owner for every lead Map<Id, List<Id>> idLeadidUsersMap = new Map<Id, List<Id>>(); // Iterate over the leads in the current batch for (Lead lead : scope) { if (lead.Owner.Type == 'User') { // Add the lead's owner ID to the set of owner IDs ownerIds.add(lead.OwnerId); idLeadidUsersMap.put(lead.Id, new List<Id>{lead.OwnerId}); } else if (lead.Owner.Type == 'Queue') { // Add the lead's owner ID to the set of queue IDs queueIds.add(lead.OwnerId); } } // create map to store list of Queue users by Queue Id Map<Id, List<Id>> idMap = new Map<Id, List<Id>>(); // create map of Group Member of the Queue Id Map<Id, GroupMember> memberMap = new Map<Id, GroupMember>([SELECT UserOrGroupId, GroupId FROM GroupMember WHERE GroupId = :queueIds]); // iterate over Group Member to create Map list of Users in Queue for(GroupMember member : memberMap.values()) { ownerIds.add(member.UserOrGroupId); List<Id> tempList = new List<Id>{member.UserOrGroupId}; if(idMap.containsKey(member.GroupId)) { tempList = idMap.get(member.GroupId); tempList.add(member.UserOrGroupId); } idMap.put(member.GroupId, tempList); } // iterate over lead records collect list of users per lead for (Lead lead : scope) { if(lead.Owner.Type == 'Queue' && idMap != null && idMap.get(lead.OwnerId) != null) { idLeadidUsersMap.put(lead.Id, idMap.get(lead.OwnerId)); } } // Query the owners and their details using the owner IDs Map<Id, User> ownerMap = new Map<Id, User>([ SELECT Id, Name, Email, ManagerId FROM User WHERE Id IN :ownerIds ]); // Create a set to store manager IDs Set<Id> managerIds = new Set<Id>(); // Iterate over the owner records to collect manager IDs for (User owner : ownerMap.values()) { system.debug('User : ' + owner.ManagerId); if (owner.ManagerId != null) { // Add the owner's manager ID to the set of manager IDs managerIds.add(owner.ManagerId); } } // Query the managers and their details using the manager IDs Map<Id, User> managerMap = new Map<Id, User>([ SELECT Id, Name, Email FROM User WHERE Id IN :managerIds ]); for(Lead lead : scope) { for(Id iduser : idLeadidUsersMap.get(lead.Id)) { // Retrieve the lead's owner from the ownerMap User owner = ownerMap.get(idUser); system.debug('lead Id : ' + lead.Id + ' -- owner : ' + owner.Id + ' -- Manage : ' + owner.ManagerId); // Create an email message Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Set the recipient (owner's email address) email.setToAddresses(new List<String>{ owner.Email }); // Add owner's manager's email to cc recipients if available if (owner.ManagerId != null && managerMap.containsKey(owner.ManagerId)) { User manager = managerMap.get(owner.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { email.setCcAddresses(new List<String>{ manager.Email }); system.debug('email.setCcAddresses'); } } // Set the email subject and body email.setSubject('Lead Still not actioned upon'); email.setPlainTextBody('Dear ' + owner.Name + ',\n\n' + 'This is a notification regarding the lead with the status "Open - Not Contacted" that was created within the last 4 hours.\n\n' + 'Lead Record: ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + lead.Id + '\n\n' + 'Thank you.\n\n' + 'Best Regards,\n' + 'Your Company'); // Add the email message to the map using the lead's owner ID as the key emailMap.put(lead.OwnerId, email); } } // Iterate over the leads in the current batch /* for (Lead lead : scope) { if (lead.Owner.Type == 'User') { // Retrieve the lead's owner from the ownerMap User owner = ownerMap.get(lead.OwnerId); // Create an email message Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Set the recipient (owner's email address) email.setToAddresses(new List<String>{ owner.Email }); // Add owner's manager's email to cc recipients if available if (owner.ManagerId != null && managerMap.containsKey(owner.ManagerId)) { User manager = managerMap.get(owner.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { email.setCcAddresses(new List<String>{ manager.Email }); } } // Set the email subject and body email.setSubject('Lead Still not actioned upon'); email.setPlainTextBody('Dear ' + owner.Name + ',\n\n' + 'This is a notification regarding the lead with the status "Open - Not Contacted" that was created within the last 4 hours.\n\n' + 'Lead Record: ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + lead.Id + '\n\n' + 'Thank you.\n\n' + 'Best Regards,\n' + 'Your Company'); // Add the email message to the map using the lead's owner ID as the key emailMap.put(lead.OwnerId, email); } else if (lead.Owner.Type == 'Queue') { // Retrieve the queue users associated with the lead's queue List<User> queueUsers = [SELECT Id, Name, Email, ManagerId FROM User WHERE Id IN (SELECT UserOrGroupId FROM GroupMember WHERE GroupId = :lead.OwnerId)]; // Iterate over the queue users for (User queueUser : queueUsers) { // Create an email message Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Set the recipient (queue user's email address) email.setToAddresses(new List<String>{ queueUser.Email }); // Add queue user's manager's email to cc recipients if available if (queueUser.ManagerId != null && managerMap.containsKey(queueUser.ManagerId)) { User manager = managerMap.get(queueUser.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { email.setCcAddresses(new List<String>{ manager.Email }); } } // Set the email subject and body email.setSubject('Lead Still not actioned upon'); email.setPlainTextBody('Dear ' + queueUser.Name + ',\n\n' + 'This is a notification regarding the lead with the status "Open - Not Contacted" that was created within the last 4 hours.\n\n' + 'Lead Record: ' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + lead.Id + '\n\n' + 'Thank you.\n\n' + 'Best Regards,\n' + 'Your Company'); // Add the email message to the map using the queue user's ID as the key emailMap.put(queueUser.Id, email); // CC the manager of the queue user if available if (queueUser.ManagerId != null && managerMap.containsKey(queueUser.ManagerId)) { User manager = managerMap.get(queueUser.ManagerId); if (manager != null && !String.isBlank(manager.Email)) { emailMap.get(queueUser.Id).setCcAddresses(new List<String>{ manager.Email }); } } } } } */ // Send the email messages Messaging.sendEmail(emailMap.values()); } // Finish method for post-processing after the batch job finishes public void finish(Database.BatchableContext context) { // Do any post-processing after the batch job finishes } }
I hope this also fixes your issue.
Regards,
Abdul Aziz Khatri

how to set up discussion forums on our salesforce community
We would like our customers to be able to have discussions based on our own products?



You can enable "Allow discussion threads" as mentioned in
https://help.salesforce.com/s/articleView?id=sf.networks_chatter_threaded_discussions_enable.htm&type=5
Also see https://salesforce.stackexchange.com/questions/375093/adding-a-forum-to-an-existing-experience-cloud-site
https://salesforce.stackexchange.com/questions/107645/is-it-possible-to-create-a-user-forum-in-communities
If this information helps, please mark the answer as best. Thank you


Hi Sonali,
To display an image in an Aura component using a static resource, you can follow these steps:
1. Upload the image to a Static Resource:
- Go to Setup in your Salesforce org.
- In the Quick Find box, search for "Static Resources".
- Click on "Static Resources" under the "Develop" section.
- Click on the "New Static Resource" button.
- Enter a name for the static resource (e.g., "MyImage").
- Choose the image file from your local system by clicking on "Choose File" or dragging and dropping the file.
- Click "Save" to upload the image as a static resource.
- Create or open the Aura component file (e.g., MyComponent.cmp).
- Inside the component markup, add an `<img>` tag to display the image.
- Set the `src` attribute of the `<img>` tag to the URL of the static resource.
<aura:component> <img src="{!$Resource.MyImage}" alt="My Image" /> </aura:component>
3. Save and deploy the Aura component:
Hope this will be Helpful.
Thanks!

I have a requirement i need to add couple of columns in Recently viewed cases list view
Please help me




Try below steps.
- From Setup, at the top of the page, select Object Manager.
- Click the label name of the object for the Recently Viewed list you want to modify.
- From the menu of links at the top of the page, click Search Layouts.
- In the far right of the Search Results row, click and select Edit.
- Recently viewed lists use the Search Results search layout in Lightning. In Classic, recently viewed lists use the Tab search layout.
- To add columns to the Recently Viewed list, select one or more fields from Available Fields and click Add. To remove columns, select one or more fields from Selected Fields and click Remove.
- Order columns by selecting one or more fields from Selected Fields and clicking Up or Down.
- Click Save.
Please mark as Best Answer if above information was helpful.
Thanks,

Compare two values from a picklist
the picklist is Customer, Prospect, Competitor
I want to do this with a row level formula for example
If company 1 = TRUE, and company 2 = TRUE it is Company 1 and 2
if comapny 1 = TRUE and company 3 = TRUE it is Comapny 1 and 3
if comapny 2 = TRUE and company 3 = TRUE it is Company 2 and 3




To compare the number of customer accounts between three companies and generate a row-level formula, you can use a combination of logical conditions and formula fields. Here's an example of how you can achieve this:
Please use this below formula for the same :
IF( ISPICKVAL(Company1_c, "Customer") && ISPICKVAL(Company2c, "Customer") && ISPICKVAL(Company3_c, "Customer"), "Company 1, 2, and 3", IF( ISPICKVAL(Company1_c, "Customer") && ISPICKVAL(Company2_c, "Customer"), "Company 1 and 2", IF( ISPICKVAL(Company1_c, "Customer") && ISPICKVAL(Company3_c, "Customer"), "Company 1 and 3", IF( ISPICKVAL(Company2_c, "Customer") && ISPICKVAL(Company3_c, "Customer"), "Company 2 and 3", "" ) ) ) )Replace Company1_c, Company2c, and Company3_c with the actual API names of the picklist fields representing the three companies.
If this helps , please mark this as Best Answer.
Thank you.

Validation Rule for REGEX is triggering even if I type the phone number per the pattern
I need to right a validation rule that allows certain phone number patterns but when I follow the pattern the rule still gets an error. Here's the Validation rule:
AND(
NOT(ISBLANK( Phone )),
NOT(
OR(
REGEX( Phone , "\\s*\\(\\d{3}\\)_\\d{3}-\\d{4}\\s*$"),
REGEX( Phone , "\\s*\\+?1_\\(\\d{3}\\)_\\d{3}-\\d{4}\\s*$"),
REGEX( Phone , "\\s*\\(\\d{3}\\)_\\d{3}-\\d{4}_x\\d+\\s*$"),
REGEX( Phone , "\\s*\\(\\d{3}\\)_\\d{3}-\\d{4}_Ext\\.\\d+\\s*$"),
REGEX( Phone , "\\s*\\(\\d{3}\\)_\\d{3}-\\d{4}_ext:\\d+\\s*$")
)
)
)




Please try with the below validation rule :
AND( NOT(ISBLANK(Phone)), NOT( OR( REGEX(Phone, "\\s*\\(\\d{3}\\)\\s*\\d{3}-\\d{4}\\s*$"), REGEX(Phone, "\\s*\\+?1\\s*\\(\\d{3}\\)\\s*\\d{3}-\\d{4}\\s*$"), REGEX(Phone, "\\s*\\(\\d{3}\\)\\s*\\d{3}-\\d{4}\\s*x\\d+\\s*$"), REGEX(Phone, "\\s*\\(\\d{3}\\)\\s*\\d{3}-\\d{4}\\s*Ext\\.\\d+\\s*$"), REGEX(Phone, "\\s*\\(\\d{3}\\)\\s*\\d{3}-\\d{4}\\s*ext:\\d+\\s*$") ) ) )
If this helps , please mark this as Best Answer.
Thank you.

I have a requirement I want to Count all total case records and count of Which case status was New
I have a requirement I want to Count all total case records and count of Which case status was New


Hi ss,
To count the total number of Case records and the number of Case records with the status "New" in Salesforce, you can use a SOQL query.
Integer totalCases = [SELECT COUNT() FROM Case]; Integer newCases = [SELECT COUNT() FROM Case WHERE Status = 'New']; System.debug('Total Cases: ' + totalCases); System.debug('New Cases: ' + newCases);Hope this will be helpful.
Thanks!

Passing multiple id's in parameter for a SOQL query
Very new to apex development but looking to pass through multiple known id's to a custom VF page to return details of accounts details.
Is this possible and does anyone have any examples.
Thanks in advance



Yes, it is possible to pass multiple IDs to a custom Visualforce page to return details of accounts. You can do this by using the ids parameter in the page's URL. The ids parameter should be a comma-separated list of account IDs. For example, the following URL would pass the IDs of accounts 0012345678901234, 0012345678901235, and 0012345678901236 to the page:
/apex/MyCustomPage?ids=0012345678901234,0012345678901235,0012345678901236Once the page has received the IDs, you can use them to query the Account object. For example, the following code would query the Account object for all accounts with the IDs that were passed to the page:
public List<Account> getAccountDetails(List<Id> accountIds) { return [SELECT Id, Name, Industry, Phone FROM Account WHERE Id IN :accountIds]; }Here is an example of a custom Visualforce page that can be used to display the details of accounts that have been passed to the page:
<apex:page controller="YourController"> <apex:form> <apex:pageBlock> <apex:pageBlockTable value="{!accountDetails}" var="account"> <apex:column value="{!account.Name}" /> <apex:column value="{!account.Industry}" /> <apex:column value="{!account.Phone}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Controller class
public class YourController { public List<Account> accountDetails { get; set; } public YourController() { List<Id> accountIds = ApexPages.currentPage().getParameters().get('ids').split(','); accountDetails = getAccountDetails(accountIds); } public List<Account> getAccountDetails(List<Id> accountIds) { return [SELECT Id, Name, Industry, Phone FROM Account WHERE Id IN :accountIds]; } }
If this information helps, please mark the answer as best. Thank you
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
If this information helps, please mark the answer as best. Thank you