You need to sign in to do that
Don't have an account?

An account can have only one oppty record created per day.
Hi All,
I have a scenario where I need to have an account to havev only one opportunity created per day.
Can anybody provide me with the best configuration solution for this.
I have a scenario where I need to have an account to havev only one opportunity created per day.
Can anybody provide me with the best configuration solution for this.
WOKRFLOW , PROCESS BUILDER AND ROLLUPSUMMERY will not works
Try the below code
trigger oppo on Opportunity(before insert) {
if (Trigger.isBefore && Trigger.isInsert) {
List<Id> positions_ids = new List<Id>();
// get the positions ids
for(Opportunity j : Trigger.new) {
positions_ids.add(j.AccountId);
}
// query all job postings for those positions
List<Opportunity> other_jobs = [SELECT Id, CreatedDate, CreatedById FROM Opportunity WHERE Opportunity.AccountId IN :positions_ids];
for (Opportunity j : Trigger.new) {
for (Opportunity existent_record : other_jobs) {
// check if we are comparing two records for the same position
// if the created date for the existing record equals the current date
// (that is, the insertion date for the record on Trigger.new), then
// we can send that error to the user.
Date existent_record_created_date = existent_record.CreatedDate.date();
if (existent_record_created_date == Date.today()) {
j.addError('Cannot create opportunity because there\'s another one created on this date.');
}
}
}
}
}
Thanks,
Selva
SPT