You need to sign in to do that
Don't have an account?
lucky25
trigger
create account no field in account object then write
if u choose industry= apparel account no=1,next u choose industry= apparel accountno=2 like wise increase corect it please
trigger num on Account (before insert,before update ,after insert)
{
string Apparel,Education,Banking;
Account[] acct=Trigger.new;
for(Account a:acct)
{
if(a.Industry==Apparel)
{
a.account_no__c=1;
a.account_no__c++;
}
else if(a.Industry==Education)
{
a.account_no__c=1;
a.account_no__c++;
upsert a;
}
else if(a.Industry==Banking)
{
a.account_no__c=1;
a.account_no__c++;
upsert a;
}
}
}
Hi,
You could use the Custom setting to save the current record count for industry and in Trigger, get the count from Custom setting to initialize the variable and at the end again save the count in custom setting.
trigger num on Account (before insert)
{
string Apparel,Education,Banking;
Account[] acct=Trigger.new;
for(Account a:acct)
{
if(a.Industry=='Apparel')
{
Integer i=[SELECT COUNT() FROM Account WHERE a.Industry=='Apparel'];
a.account_no__c=i++;
}
else if(a.Industry=='Education')
{
Integer i=[SELECT COUNT() FROM Account WHERE a.Industry=='Education'];
a.account_no__c=i++;
}
else if(a.Industry=='Banking')
{
Integer i=[SELECT COUNT() FROM Account WHERE a.Industry=='Banking'];
a.account_no__c=i++;
}
}
}
if it resloved your question please mark it as resolved.
Mind explaining to us why you want to run your trigger on before insert, before update and after insert ? (I would like you to think about it)
In the example provided, SOQL should not be written inside the For loop.
Instead of SOQL, Custom setting will work like charm !!!
Hi Jitendra
can you expalin what is custom settings and how can we do or provide some links.
Hi,
Custom Setting Details,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm
Useful blogs from Jeff Douglas,
http://blog.jeffdouglas.com/2010/02/08/using-hierarchy-custom-settings-in-salesforce-com/
http://blog.jeffdouglas.com/2010/01/07/using-list-custom-settings-in-salesforce-com/
Hope this helps :)
Thanks,
Devendra