You need to sign in to do that
Don't have an account?
Need Help ..
Hi All,
My Requirement is
Account Is Record Type="Master Account Layout' and parent account is Null then HQ field set to True
I have Created a trigger for achieving above reqt
1 2 3 4 5 6 7 8 9 10 11 | trigger accountTypeChange on Account (before Insert) {
But as I want to insert the record on Account Object I am getting the error msg
"Error: Invalid Data.
Plz Help me in rectifying the Issue.. |
Hi you can try like this ,it may helpful to you
Don't write Dml operation in for loop, it will Exception when cross governor limitations.
trigger accountTypeChange on Account (before Insert) {
List<Account> varacc=new List<Account>();
for(Account acc :Trigger.new){
If(acc.Record_Type__c == 'Master Account Layout' && (acc.Parent == null || acc.Parent.Record_Type__c == 'Virtual Acount Partner'))
{
acc.HQ__c =true;
varacc.add(acc);
}
}
update varacc;
}
If it is helpful plz make it as solution for others it may benfit
Prem
All Answers
Hi you can try like this ,it may helpful to you
Don't write Dml operation in for loop, it will Exception when cross governor limitations.
trigger accountTypeChange on Account (before Insert) {
List<Account> varacc=new List<Account>();
for(Account acc :Trigger.new){
If(acc.Record_Type__c == 'Master Account Layout' && (acc.Parent == null || acc.Parent.Record_Type__c == 'Virtual Acount Partner'))
{
acc.HQ__c =true;
varacc.add(acc);
}
}
update varacc;
}
If it is helpful plz make it as solution for others it may benfit
Prem
I think this still has some issues - try this:
You never need to - or want to - perform DML on the record you are processing in a before trigger.
Hope this helps,
Hi John,
Good Morning,
Thanks for you reply..
The problem is Resolved
Actually The basic thing that I forget and as you say
"You never need to - or want to - perform DML on the record you are processing in a before triggers you say "