[SalesForce] The record should be created only once for an object

For a product only one once an incentive can be created according to this business process how can i restrict it form creating more than one record.

Best Answer

I agree with what Birthus outlined but that will not work if using the API instead of the UI. You need some sort of validation using an insert trigger. It would essentially check the value of the rollup summary field and if the value is currently greater than 0, reject the insert.

trigger IncentiveTrigger on Incentive (before insert) {
  for (Incentive i : Trigger.new) {
    if (i.Opportunity__c.rollup_field__c > 0) {
        // throw your error
    }
  }
}
Related Topic