+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

Set new field values and increment

Hello All,
I have an issue and not sure how to approach it.
I have a Parent record 'Product'
And multiple child records 'Items'
If a user inserts an item name 'Test 1' then assign field desc__c to '1000'
And if another Item record name 'Test 1' is inserted then assign field desc__c to '2000'.  This format would continue
These Item records may be dataloaded so basically the original item will have a desc__c field value of '1000' and all other records with the same name value would have a desc__c field value that is incremented by 1000.
I am not sure how to even approach this.  Aggragate all records that are being inserted and look for a count greater than 1? 
User will also be able to manually insert indivisual item record.
Any suggestions would be greatly appreciated.
Cheers,
P
Suraj Tripathi 47Suraj Tripathi 47
Hi Phuc,
You can write a trigger for the same and in that trigger, you can fetch all the records with the same name if they exist then after the count you can add the value in the desc__c field according to the value of the count.
and if the record already exists in the org then you can run the script and query the record according to the createdDate and assign the value in desc__c accordingly.
I think this might be an approach.

Please mark it as the best answer if it helps you to fix the issue.
Thank you!
Regards,
Suraj Tripathi