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

Auto numbering that is unique to each account.
Hi all,
Is there a way to have a field that will automatically create a number for each Address that I create within an Account?
- I created an Object called Location - Were we store all of our address (Billing, Shipping, Servie and Corporate)
- I created an Auto Number field called Location #.
- This field needs to auto populate with a number upon creation for reporting purposes.
- This number needs to be unique by Account.
- Currently when I create an address it numbers correctly within the first Account: 1,2,3,etc. - but when I go to another Account, it continues the numbering cycle: 4,5,6, etc.
Figured this one out too, need help with deployment though. Anyone have a how to guide on trigger deployment?
/* Loop through all locations and collect the current numbers. */ trigger LocationUpdate on Location__c (before insert) { /*Loop every new location you enter*/ for(Location__C l:trigger.new) { if(l.Location__C==null){ String cname = l.Account__c; /* This writes to the debug log*/ //System.debug('location data: '+l); /*This looks up all of the location numbers for the specific account*/ List <Location__c> a = [select location__c from Location__C where ACCOUNT__C= :cname ]; /*If the list results are empty*/ system.debug(a); if(a.isEmpty()){ l.Location__C=1; }Else { List <Decimal> b = new List<Decimal>(); for (Location__C tempLocation:a) { b.add(tempLocation.Location__c); } Decimal highest = 0; b.sort(); highest = b[b.size()-1]; l.Location__C=highest + 1; } } } }