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

Hi friends! without validation rule, I wanna date Error Message on Account Obj.
ex: am trying like this but it won't workout. then how????
trigger acctrig on Account (before insert,after update) {
Account acc =new Account();
if(acc.SLAExpirationDate__c != System.today())
acc.addError('Error! enter only today date');
}
or
trigger acctrig on Account (before insert,after update) {
Account acc =new Account();
acc.today__c = date.today();
if(acc.SLAExpirationDate__c !=acc.today__c)
acc.addError('Error! enter only today date');
}
so pls share anather better sample code for this.
Hi Das,
Your asking about for loop as you know this loop for new trigger memory allocation.
It takes the values from current record and Existing records.
Account a=new Account();
It is used for Appending or Adding records to that Object.And Take the values from existing records.
So our critiria reaches using for loop way..
Ok if you satisfied with above answer please make it as Soluble .. For Other's it may benifit.
Regards
Prem
All Answers
Hi DasG,
Follow this code it's working now..
trigger acctrig on Account (after insert,after update) {
for(Account acc :trigger.new){
Datetime cDT = Date.Today();
System.Debug('reocrd date=====>'+acc.Today__c);
System.Debug('----->'+cDT);
if(acc.Today__c!=cDT){
acc.addError('Error! enter only today date');
System.Debug('------>inner loop------------------->');
}
else{
System.Debug('----------->Outerloop-->');
}
}
}
Hi DasG,
Here you are creation the instance of account and trying to check that data and you are not validation the account which causes the trigger that is the problem with your code. So please update your code with code given by “Premanath” which will work for you.
Hi Das,
Your asking about for loop as you know this loop for new trigger memory allocation.
It takes the values from current record and Existing records.
Account a=new Account();
It is used for Appending or Adding records to that Object.And Take the values from existing records.
So our critiria reaches using for loop way..
Ok if you satisfied with above answer please make it as Soluble .. For Other's it may benifit.
Regards
Prem