You need to sign in to do that
Don't have an account?
Help with a trigger to prevent the creation of new accounts.
I have written a trigger to prevent the creation of new accounts, and it works fine via UI but not via Lead Convert tool. Any ideas?
I eventually will add a filter so restrict a certain set of users (by profile) to not be able to create accounts but just testing it in a simple format to see if the account creation prevention works but it is not working when new accounts get created via lead conversion process.Any ideas?
Here's my code:
trigger PreventNewAcctCreation on Account (before insert)
{
for (Account act : Trigger.new)
{
act.addError('You do not have access to create new Accounts');
}
}
Go to setup->App setup -> Customize-> Leads-> settings and check the box called "Enforce Validation and Triggers from Lead Convert" then your trigger would work.
All Answers
Go to setup->App setup -> Customize-> Leads-> settings and check the box called "Enforce Validation and Triggers from Lead Convert" then your trigger would work.
Thanks SaiKishore, but i dont see "Enforce Validation and Triggers from Lead Convert" under App setup -> Customize-> Leads-> settings
Here are the only settings i see under Lead Conversion Settings -
Do Not Change Lead Status Values to New Owner's Record Type on Lead Conversion
The behavior used when applying assignment rules to manually created records. Keep the existing record type Override the existing record type with the assignee's default record type
That is strange. if it is not visible then may be you will have to contact salesforce support.
Look at this post
http://boards.developerforce.com/t5/forums/forumtopicprintpage/board-id/apex/message-id/48277/print-single-message/false/page/1
Great Thanks. I have logged a case w SFDC support they say it will take up to a day to do it.
Btw once it is enabled, does it mean that the Apex trigger i have under Accounts to prevent new Accounts from being created wil work during account creation via lead conversion as well.
Or will i have to create a new trigger under Leads. If so, do you have any tips on how to create a trigger under Leads such that to prevent creating a new account during lead conversion? Thanks much Sangeeta
Once enabled your trigger on Account will work for sure. You do not have to write any trigger on lead.
Awesome thanks.
Btw can you give me some tips on how to add to this code such that it applies only to certain user profile. Thanks Sangeeta
I would recommend to create a validation rule on account to prevent account creation than trigger.
Create a validation rule on account
Rulename: AccountCreatePrevention
Error Condition Formula: ISNEW() && ( $Profile.Name = 'profilename1' || $Profile.Name = 'profilename2')
Error Message: You do not have access to create account
This validation would prevent the users with profiles "profilename1" and "profilename2" to create accounts.
Hope this helps.