+ Start a Discussion
Hi All,
Help me on this, i want using validation rule "Dealer user cannot save if the selected picklist value in Status field in "Inquiry" record type in Case is "Uploaded".
Best Answer chosen by sanjusfdc
Prakash NawalePrakash Nawale

Use below code in validation rule to prevent creating of Case record based on your requirments.
            $User.Username = 'Dealer username',
            ISPICKVAL( Status , 'Uploaded') 

Please like the answer and mark it as best if this helps.
Craig WoodmanCraig Woodman 
I had a question, but answered it on my own. So since my search didn't reveal anything, I figured I would post it here in case anyone else is looking.

Does a Before Update flow (or one that is triggered by record create or change, that saves before the record is updated) work with lead creation by web-to-lead?

I had not seen this in any documentation. And searches didn't show anything. So I figured I would do some tests on my own.

I set up a test flow to write text to the Lead Description field on creation, that says "The before update flow worked!!!" I then went to the website, downloaded a catalog, and checked the description field. The text was written, with no delay to the web to lead record.

My use case for this is changing the record type automatically on a web to lead record, which passes in certain values. It works perfectly!

I hope that this helps anyone who is looking for this information!
Best Answer chosen by Craig Woodman
Craig WoodmanCraig Woodman
Thanks Anutej,  While this can be completed with a trigger, I wanted to show the functions of the new before save flow actions, and answer a question that I could not find about these flows.  Hopefully people can see this and see both solutions.
Pete Watson 5Pete Watson 5 
Hi All, 

Any help on the below would be much appreciated.

have the below trigger and its working perfectly in the sandbox but after deploying to prod I am getting a CPU time limit exeeded failure... 

trigger ProfileTrigger on User (before insert, before update) {
    List<Id> userIds = new List<Id>();
    List<Case> cases = new List<Case>();
    List<Case> casesToUpdate = new List<Case>();
    for(User u: Trigger.new) {
        if(u.out_of_office__c==True) {
        for (case c : (cases = [SELECT id, Status FROM Case where ownerId IN:userIds]))
            IF(c.Status == 'Assigned' || c.Status == 'Working' ||c.Status == 'Escalated'){
        update casesToUpdate;

Many thanks in advance! 
Best Answer chosen by Pete Watson 5
AnudeepAnudeep (Salesforce Developers) 
Hi Pete, 

I recommend adding Limits.getCpuTime() to check where there is the maximum consumption is
Integer cpuStart = Limits.getCpuTime();
System.debug('Before For loop = ' +cpuStart);

    for(User u: Trigger.new) {
        if(u.out_of_office__c==True) {
 System.debug('CPU time consumed in loop ' + (Limits.getCpuTime() - cpuStart));

// repeat this for the other for loop

// Check CPU time before DML

 cpuStart = Limits.getCpuTime();

 System.debug('Before DML = ' +cpuStart);

 update casesToUpdate;

I suggest comparing the debug logs between your sandbox and production when running this code

Also, review this help article



I have always this error when i try to deploy a flow
The version of the flow you're updating was active and can't be overwritten
I have disactivated the flows adn process builder related, but i still have error.

Can someone suggest me wht i can do ?
Best Answer chosen by Sandrine
Hope E.Hope E.
Hi Sandrine,

this might help:
Michael MMichael M 
Hello, I was wondering if someone can help me write the apex to parse a string like this (changed the details of it, but the concept is still what I need):


From that string, I only want everything between "https://" and ".facilities...". Also, I want to replace the "-" with spaces, and capitalize each word. So from the above string, I would want it to say "Abc Park Store". How can I parse the string as such? Thank you.
Best Answer chosen by Michael M
AnudeepAnudeep (Salesforce Developers) 
Hi Michael, 

Verified in my org. The following code gives the output you are looking for
String str = 'https://abc-park-store.facilities.facilities.org/contact-form-block/';
String str2 = str.substringAfter('//').substringBefore('.facilities'); 
System.debug('split string is' + str.substringAfter('//').substringBefore('.facilities')); 
System.debug('string' + str2.substring(0,1).toUpperCase()+str2.substring(1,3)+'-'+str2.substring(4,5).toUpperCase()+str2.substring(5,8)+'-'+str2.substring(9,10).toUpperCase()+str2.substring(10,14));

I referred to the methods available in the string class

Let me know if it helps

Sonam PatilSonam Patil 
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 a.Name.addError('Name already Exist ');
Best Answer chosen by Sonam Patil
Amit Chaudhary 8Amit Chaudhary 8
Never use Soql without any filter or limit. Once account count will inc your code will fail

Please try below code.
trigger AccountDuplicate on Account (before insert)

	Set<String> setName = new Set<String>();
	For(Account acc : trigger.new)
	if(setName.size() > 0 )
		List<Account> lstAccount = [select name ,id from account where name in :setName ];
		Map<String ,Account> mapNameWiseAccount = new Map<String,Account>();
		For(Account acc: lstAccount)
			mapNameWiseAccount.put(acc.name ,acc);
		For(Account acc : trigger.new)
				acc.Name.addError('Name already Exist ');

Please check below post for trigger. I hope that will help you
1) http://amitsalesforce.blogspot.com/search/label/Trigger
2) http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html

Trigger Best Practices | Sample Trigger Example | Implementing Trigger Framework

1) One Trigger Per Object
A single Apex Trigger is all you need for one particular object. If you develop multiple Triggers for a single object, you have no way of controlling the order of execution if those Triggers can run in the same contexts

2) Logic-less Triggers
If you write methods in your Triggers, those can’t be exposed for test purposes. You also can’t expose logic to be re-used anywhere else in your org.

3) Context-Specific Handler Methods
Create context-specific handler methods in Trigger handlers

4) Bulkify your Code
Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time.

5) Avoid SOQL Queries or DML statements inside FOR Loops
An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. So if this trigger is invoked by a batch of more than 100 Account records, the governor limit will throw a runtime exception

6) Using Collections, Streamlining Queries, and Efficient For Loops
It is important to use Apex Collections to efficiently query data and store the data in memory. A combination of using collections and streamlining SOQL queries can substantially help writing efficient Apex code and avoid governor limits

7) Querying Large Data Sets
The total number of records that can be returned by SOQL queries in a request is 50,000. If returning a large set of queries causes you to exceed your heap limit, then a SOQL query for loop must be used instead. It can process multiple batches of records through the use of internal calls to query and queryMore

8) Use @future Appropriately
It is critical to write your Apex code to efficiently handle bulk or many records at a time. This is also true for asynchronous Apex methods (those annotated with the @future keyword). The differences between synchronous and asynchronous Apex can be found

9) Avoid Hardcoding IDs
When deploying Apex code between sandbox and production environments, or installing Force.com AppExchange packages, it is essential to avoid hardcoding IDs in the Apex code. By doing so, if the record IDs change between environments, the logic can dynamically identify the proper data to operate against and not fail
Haneesh reddy 13Haneesh reddy 13 

With the Salesforce API, is there any way to get the current time on the Salesforce server?

Can any one please help me out.
Best Answer chosen by Haneesh reddy 13
AbhishekAbhishek (Salesforce Developers) 
Yes, you can use the getServerTimestamp() method:

GetServerTimestampResult timestamp = binding.getServerTimestamp();

See Salesforce API Docs: getServerTimestamp() (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm)

User-added image

I have created two LWC component and in my prop.html I want to add lWC component.

    <ligthning-input label="percentage" type="number" min="0"
    max="100" value={percentage} onchange={changepercent}></ligthning-input>   
    <c-lwc percentage={percentage}></c-lwc>

When I try to push this to my scratch org I am getting the following error

User-added image

I am new to LWC
Best Answer chosen by sevindu
sfdcDeveloper 12sfdcDeveloper 12
Can you rename your lwc component to some other name
I am having trouble completing the challenge for the "Create and Edit Lightning Components" module of the "Lightning Components Basics" trail. Here is the challenge:

Create a camping component that contains a campingHeader and a campingList component.
    The campingList component contains an ordered list of camping supplies that include Bug Spray, Bear Repellant, and Goat Food.
    The campingHeader component contains an H1 heading style with a font size of 18 points and displays 'Camping List'.

Here is my code:


<aura:component >   


<aura:component >
    <H1>Camping List</H1>



    font-size: 18px;


<aura:component >
    <aura:attribute name="campingSupplies" type="List" default="['Bear Repellant', 'Bug Spray', 'Goat Food']" />

When I check the challenge, I get the error message:

Challenge Not yet complete... here's what's wrong:
The component is not using the correct font size.

Any help is greatly appreciated.
Best Answer chosen by MatK62
Nayana KNayana K

<aura:component >
<li>Bear Repellant</li>
<li>Bug Spray</li>
<li>Goat Food</li>



    font-size: 18pt;
Michael MMichael M 
Hello, we need to give access to a user to login as other users. However, we do not want them to be able to edit meta-data, and preferably we don't want them to be able to login as system administrators. 

 I am trying to use the "delegated administrator" feature, however, I don't see how to give them the ability to login as other users without giving them the "modify all data" permission, but the problem is that gives them access to metadata. Is there any way around this? 
Best Answer chosen by Michael M
ShirishaShirisha (Salesforce Developers) 
Hi Michael,


If you need some other user to login as other user then that user should have the Modify All Data permission which will allow the user to access the Metadata as well.

So,it is not possible to provide the login as user access without having the Modify All Data permission.

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri