0

i have a a/c id field, this field should be updated with country ISO Code 3 digits and numeric value incremented per country when I create a bank account in China, it auto populate the A/C ID with CHN001

then if I create a second bank account it auto populate CHN002 when I create another bank account for France it auto populates FRA001 even if this is the third bank account, it is the first in France

Please let me know if any ideas

1

You need an update trigger on the object (i dont know the name). Try something like following. I just pre-assumes your object and field names.

trigger ACUpdate on X (before update,before create){

    //get incoming countries
    set<String> incomingCountry = new set<String>();
    for(r in Trigger.New){
        incomingCountry.add(r.CountryIsoCode__c);
    }

    //Then aggregate query
    list<AggregateResult> aggResult = [select cnt COUNT(Id),iso CountryIsoCode__c from X where CountryIsoCode__c IN:incomingCountry group by CountryIsoCode__c];
    map<String,Integer> countryToMax = new map<STring,Integer>();
    for(AggregateResult ag : aggResult){
        countryToMax.put((string)ag.get('iso'),(Integer)ag.get('cnt'));
    }
    //Last for and update 
    for(r in Trigger.New){
        r.acid__c = r.CountryIsoCode__c.substring(0,3) + '' + countryToMax.get(CountryIsoCode__c)+1;
    }
}
  • Thanks erkan for your response, here i am looking to update without code. So if you have any ideas please let me know – prasad nagamalli Mar 10 '17 at 12:09
  • I see, i guess it seems to be not possible but will let you know if any idea comes up... – erkan çipil Mar 10 '17 at 12:21
  • if there is a master-detail relationship between object , you may utilize a roll up field in order to get max value on that cuntry. Then it will be easier. – erkan çipil Mar 10 '17 at 12:23
  • Yes, it has a master detail relationship and that is the master object, can u please explain how it is possible – prasad nagamalli Mar 11 '17 at 5:33
0

Ok then let's say you have a country object that has following fields 1- Name 2- ISO CODE 3- Count(roll up summary) then the other ( say another__C) object that has master detail field to country 1- Country (master-detail) 2- Holding__c A number field 3- A/C__c A formula field (a/c) You need to create a workflow rule on create another__c that stick the roll up number to the holding field.

Then your a/c formula field should look like :

Holding__c &''& Country__r.ISO_Code__c

So you will be able to achieve your requirement without coding.

enter image description here

  • Thanks erkan, I already did the same thing what you suggested, it worked for me – prasad nagamalli Mar 14 '17 at 7:02
  • Great...Im glad it helped... – erkan çipil Mar 16 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.