2

I want Salesforce to generate a number on the portal it needs to go from 0000 to 9999 and it needs to be generated once the customer choses a number. eg, if the last generated number was 0021 and the customer presses 3 the numbers generated will be 0022 0023 0024. Where in salesforce would i store the last generated number only without storing all the previous numbers ? Any idea on how to approach this problem ? any guidence or tips would be usefull thank you .

  • Are you trying to reinvent an auto-number field? – Adrian Larson Feb 29 '16 at 16:19
  • By "customer" do you mean a User? If so you can add a field to the User object and increment that. – Keith C Feb 29 '16 at 16:33
  • yes by customer I mean a portal user. one that can access the community/ portal but not the salesfroce insance – Greg Mar 1 '16 at 8:24
3

You can create a custom setting (or an object in this case your object will need only 1 record that will contain that number) and store that number there. Then once it is changed just update that number.

For example create a Hierarchy Custom Setting Number Setting and add a number field there called Largest Number. Then add a default Organization Level Value - your start value i.e. 0:

Number_settings__c setting = Number_Setting__c.getOrgDefaults(); 
Double largest = setting.Largest_Number__c;

// Display value of the variable largest where you need to 
// Do some manipulations i.e. increment your number
// Assign your largest number to a variable largest

setting.Largest_Number__c = largest;
update setting;

This way that custom setting will keep your largest number.

| improve this answer | |
  • Can you add some detail to make this a more complete answer? – Adrian Larson Feb 29 '16 at 16:20
  • @AdrianLarson I've added some more details. – Oles Malkov Feb 29 '16 at 16:51
  • Why not use Hierarchy Custom Setting and getOrgDefault()? – Adrian Larson Feb 29 '16 at 16:56
  • Not too clear from the question, but I would assume there are many customers not one customer. – Keith C Feb 29 '16 at 16:57
  • I was thinking that number is one for all users. But if this is not the case we can use user Id as a name instead of Largest. Good point with hierarchy settings I'll update my answer once I'll get to my computer:) – Oles Malkov Feb 29 '16 at 17:01

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.