You need to sign in to do that
Don't have an account?
Trigger
I create a trigger which prevent user form save account if it associated with a recordtype account:
Is the following trigger correct? Do I need to put the query outside the account for loop.
Trigger UmbrellaAccountTrigger on Account (before insert,before update) {
private Account[] Acc =Trigger.new;
integer SOQL;
List <contact> Con= New List <Contact>();
For(Account a:Acc){
a.Updated__c=[select count() from contact where accountId=:a.ID];
If((a.Updated__c!= 0)&&(a.RecordTypeC__c==1 )){
a.addError('You can not save Umbrella Record associated with a contact');
}
}
}
Note: a.Updated__c is a custom field on account and it display the number of relcated contact
Yes, you should always put queries and DML statements outside of loops, that way you won't breach the governor limits no matter how many records are updated/inserted.
For this trigger, I would go for something like this:
All Answers
Yes, you should always put queries and DML statements outside of loops, that way you won't breach the governor limits no matter how many records are updated/inserted.
For this trigger, I would go for something like this:
Thanks, that's help.
But i still get an exception error because of workflow of (RecordTypeC__c ) custom field on Account
on My account organization I have 3 Record type: Umbrella/Office/NoCompany
if want write a statement: what is the data Type of record type of account ? Recordtype ?
instead of : if (cons.Size()!=o && a.ReportTypeC==1) ;
I Want write the following statment: if(cons.Size() !=0 && a.ReportType='Umbrella') ? still i get apex compiler error because of data type.
Many thanks for your help