function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mdangondmdangond 

Account Insert Apex Trigger & Account Name Validation

Thanks so much SelectedPartner. This solution worked!

 

But now I need to improve on this logic just a little bit and I need to validate that the account name is following our naming standard. Our Account naming standard is "Company Name - Site City", where Site City is a custom field that has the name of the city where the company is located. So what I am now trying to do is to add one or two more lines of code that will do the following:

 

1. Check that the company name has a " - " in its name.

2. Check that the Site City value (which is required) is also part of the name.

 

Example: IBM - San Francisco is the correct way to name the IBM account in San Francisco. So anything like just "IBM" would be invalid. "IBM - "would also be invalid, since it's missing the city name at the end of the name. "IBM - Boston", with a Site City = San Francisco would also be invalid since Boston is not equal to the value of Site City, in this case, San Francisco.

 

In summary: Is there a way to check for the existance of " - " and a matching value of Site City on the new account name a user is trying to create? If this is true, can you please give me an example of how this code would look like? I'm already using your code. Thanks a million!