You need to sign in to do that
Don't have an account?
Max Alexander 19
Auto increment child object number
HI,
i hav follwing issue, on every opportunity i have deal offers its a custom object, so what i need to do is to create auto incremetn number on each deal offer idependent of opportunity, so for example
opportunity A has 2 deal offers number for them will be 1, 2
Opportunity B has 3 deal offers numbers for them would be 1,2,3
and so on so counter for deal offers are only applicable within opportunity.
i have this piece of code works fine with all new records, but when i try to insert in bulk or update in bulk it gives me duplicates
any sugestion?
i hav follwing issue, on every opportunity i have deal offers its a custom object, so what i need to do is to create auto incremetn number on each deal offer idependent of opportunity, so for example
opportunity A has 2 deal offers number for them will be 1, 2
Opportunity B has 3 deal offers numbers for them would be 1,2,3
and so on so counter for deal offers are only applicable within opportunity.
i have this piece of code works fine with all new records, but when i try to insert in bulk or update in bulk it gives me duplicates
trigger rollupChildren on Deal_Offer__c (before insert, before update) { set <id> ids = new SET<id>(); for(deal_offer__c d:Trigger.new){ ids.add(d.opportunity__c); } List<Deal_Offer__c> doList = [select id,id__c from Deal_Offer__c where opportunity__c in:ids order by id__c desc ]; for (Deal_Offer__c d:trigger.new){ IF(!doList.isempty()){ d.id__c=doList[0].id__c; } IF(doList.isempty()){ d.id__c=1; } } }
any sugestion?
Please check the below sample code(number of contacts related to the particular account).
Hope this helps you!
Best Regards,
Jyothsna