function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yuhan chen 3yuhan chen 3 

branch auto number

There are two object A B
A is a master object of B
we have set a auto number in A which goes like con-0001,con-0002,...
then we want a auto branch number in B based on A which goes like con-0001-0001, con-0001-0002,... if they are related to con-0001

How can we make this happen in Apex or standard config?

Best Answer chosen by yuhan chen 3
ANUTEJANUTEJ (Salesforce Developers) 
Hi Yuhan,

This is just an idea but you could have an auto number on the account and a trigger on contact that runs after insert that could concatenate the serial number field on account with count value on contact the update that particular record.

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Yuhan,

This is just an idea but you could have an auto number on the account and a trigger on contact that runs after insert that could concatenate the serial number field on account with count value on contact the update that particular record.

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
This was selected as the best answer
Karan KeharKaran Kehar
Hi Yuhan,

You can try this:

Create one AutoNumber field on A. con-0001
Create one Autonumber field on B 0001
Now you can create one formula field on B which concatenates Autonumber fields of B and A.

 If this helps you, can you please choose this as the best answer so that it can be used by others in the future.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Karan,

I think if the above way is done then all the contacts will have a unique number for example:

Account 1 contact-2
Id's would be: a-001-001, a-001-002
Account 2 contact-1
Id would be a-002-003

I think yuhan is mentioning that the id should be a-002-001

If that is the case then I don't think the auto number on object b might not be useful.
Karan KeharKaran Kehar
My Bad Anutej.

I agree with what you are saying.
yuhan chen 3yuhan chen 3
Thank you guys it's very helpful