You need to sign in to do that
Don't have an account?
N c
how to write a validation rule when Year and Month filed is same
i have a object and fields are Year__c and Month__c, when user is trying to insert another record with the same year and same month. we need to throw an error
Below code is just sample and may not compile.
Trigger MyObjecttInsert on MyObject(before insert)
{
for(MyObject a : Trigger.new)
{
List<MyObject > mynew = [select id, name from MyObject where year__c = :a.year__c and month__c = a.month__c];
if(mynew.size()>0)
{
a.name.addError('MyObject with Month Year existing');
}
}
}
You can do this using configuration also, mark the field as unique. Whenever a new record with a same year and month is created an error would be thrown.
Hope it helps
RD