+ Start a Discussion
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan 

Need help to prevent two numbers overlapping between records of an object..Urgent Please Help

Hi All,

I have a requirement to avoid overlapping the two number field values with in an object records creation/updation. Following are my Scenarios for preventing overlapping between records,

User-added image

From the above table the two values indicate the minimum and maximum ranges. There we can add a new record with MinRange__c = 101 and MaxRange__c = 200, because didn't overlap any of the other record's min and max value. 

But we should not allow the values MinRange__c = 10 & MaxRange__c = 70 or MinRange__c = 201 & MaxRange__c = 250 and so on, because it will fall under already created records min and max value(Overlaps).

If you see the last row, this has the -1 value as maxrange__c because this is used to indicate the infinity. It this is found in a record, we shouldn't allow another record should be created with MinRange__c > 500

Please anybody help me with a solution for this logic.

Thanks in Advance,
Kamatchi Devi R

Dev.AshishDev.Ashish
You need to use trigger for this requirement, in trigger (before insert) validate if values you are trying to insert fall between your existing ranges.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi Ashish,

I know we could do this only using trigger. But I have been trying to acheive this logic using trigger for two more days, but till this is locking in a part i couldn't do this perfect since.

So, If anybody try this and achieve this logic in trigger, please send me the code.

Thanks.
Dev.AshishDev.Ashish
Hi KamatchiDeviR,
Let me know if if you are still facing this issue, I could help you write trigger.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Thanks for your help ashish, I have done the logic through trigger