You need to sign in to do that
Don't have an account?
Pannar
unique oppotunity name check thru apex?
Hi,
If an opportunity is created for Account 123, opportunity name is Opportunity–123. If another opportunity is created for Account 123, the system will return an error if the name of the opportunity is the same as one already in SFDC.
Is it possible?
Dear Ricky,
Thank you so much for responding all of queries.
It would be great, if You could share us some sample syntax code for either trigger or validation rule.. :-)
The online help has good information on VLOOKUP, and the doc and the Developer Guide can walk you through simple triggers.
Ricky.,
ok. I wanted to compare the Opportunity Name and check whether that is already exists in the opportunity history so that we can set the unique opportunity name right? but i couldn't find opportunity history by using Insert Field button on the validation rule section. Just need to check the opportunity name in the opportunity history and throws the error if the entered opportunity already present in the history?
Please see the Salesforce wiki and documentation for examples on how to get started with Apex and triggers.
Wow! thats nice to see that trigger.
I've also written like this not sure its correct. But i am very much afraid with the error message"Too many SOQL queries, if i tried to insert more than 5000 records thru data loader! :-(
are you sure either my code or your code doesn't throw too many SOQL queries error,if we inert very huge records thru bulk load?
Yes, i expected this answer from You. :-)
To adapt this code, we need to use List, Map variable to store the bulk of opportunity names in the array and then search the loopkup opportunity name from there? I am novice to apex trigger :-(
Thanks for your help.
But like many triggers posted here yours has a problem with concurrent inserts, where concurrent inserts of the same opportunity name won't be spotted (because the other transaction hasn't committed yet, so isn't visible to your query), and in this particular case, you're not going to spot duplicates within the same batch.
Best of luck!
Yes Simon Sir, You are right. adding the statement LIMIT 1 which obviously increase the performance. :-)
If i do the batch process and transaction wouldn't able to spot the duplicate names, then what can be the solution for this? Is it limitation from Salesforce or any other approach which i need to follow.
Ron,
I've seen the Apex Governor limits" from apex api document. It says that how many maximum SOQL queries can be run in the for loop. If it exceed the limit, then we would suffer from trigger exception which would make the business user to be very unhappy.
by the way, i am working on this in the midnight india time ;-)
I hope this post is not too old to pick up from!!!
With all this great information; would there be a way to interact with the user so that they can deside if they want the duplicate record to be saved or canceled. Our business rules do allow dups for certain situations.
You can make trigger like this which will avoid Too Many SOQL queries error.
trigger noduplicate on opportunity(before insert) {
set<String> oppset=new set<String>();
for(opportunity opp : [select name from opportunity])
{
oppset.add(opp.name.toUpperCase());
}
for(opportunity newopp : Trigger.new)
{
if(oppset.contains(newart.name.toUpperCase()))
{
newopp .addError('Opportunity Already exist.');
}
}
}