You need to sign in to do that
Don't have an account?
Creating Autonumber field that reset per product entry in Opportunity
Hi,
Im a newbie in salesforce so i don't really know how to do trigger and extensive formula. I need to create a field that is Series No. that will automatically increment when an opportunity is created. However this incremental function depends on which product (custom field) has been chosen because we have a couple of products that involves a range in series.
ex.
Product 1, 2, 3 - series should belong to 0000 to 2999
Product 4, 5 - series should belong to 3000 to 3999
If Opportunity 1 is posted choosing Prod 1 series should be 00001
If Opportunity 2 is posted choosing Prod 1 (same product) series should be 00002
If Opportunity 3 is posted choosing Prod 2 (same product) series should be 00003
If Opportunity 4 is posted choosing Prod 4 (same product) series should be 30001
please help.
thanks,
cat
Hi,
You have to write the trigger on opportunity. You have to bulkily the code at your own.
Try the below code as reference:
trigger OpportunityCount on Opportunity (before insert)
{
for(Opportunity o:trigger.new)
{
system.debug('#################' +o.Product_Type__c);
if(o.Product_Type__c=='Product 1' ||o.Product_Type__c=='Product 2' ||o.Product_Type__c=='Product 3')
{
list<Opportunity> op1=[select id,TextAutoNumber__c from Opportunity where (Product_Type__c ='Product 1' or Product_Type__c ='Product 2' or Product_Type__c ='Product 3') and TextAutoNumber__c !=null order by TextAutoNumber__c desc];
if(op1.size() > 0)
o.TextAutoNumber__c =op1[0].TextAutoNumber__c + 1;
else
o.TextAutoNumber__c= 00001;
}
else if(o.Product_Type__c=='Product 4' ||o.Product_Type__c=='Product 5' )
{
list<Opportunity> op2=[select id,TextAutoNumber__c from Opportunity where (Product_Type__c ='Product 4' or Product_Type__c ='Product 5') and TextAutoNumber__c !=null order by TextAutoNumber__c desc];
system.debug('@@@@@@@@@@@@@' + op2.size());
if(op2.size() > 0)
o.TextAutoNumber__c =op2[0].TextAutoNumber__c + 1;
else
o.TextAutoNumber__c= 30001;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hello,
Thank you for your email. sorry it took me more than 1 year to check this answer. Actually i couldn't understand most part of it. but i'll try to test it and will get back to you.
can you please make some comments on what line pertains to.
thank you very much.
cat