I am practicing building triggers in Salesforce. I have a trigger that creates an opportunity record automatically when an account record's Type field is "Prospect". How can I take this trigger further by limiting the number of opportunities created to just one? For instance, every time a person updates the account record to "Prospect", it will create a new opportunity which I do not want since one was created already.
trigger createOppty on Account (after update) {
list <Opportunity> Opptylist = new list <Opportunity>();
for (Account o : trigger.new){
if (o.Type == 'Prospect') {
Opportunity Oppty = new Opportunity(
AccountId = o.Id,
Name = 'Edit Opportunity',
CloseDate = system.today(),
StageName = 'Prospecting');
Opptylist.add(Oppty);
}
insert Opptylist;
}
}