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
Jeremy KJeremy K 

sequence number on child object

I have 2 objects "Ticket and Ticket Item"  they have a master detail relationship with Ticket as master. I need to set up a number sequence by 10 on “ticket item”
 
The way I need it to work is every time a “ticket item” is added to a ticket is get a Sequence number starting at 10. The sequence would jump by 10 for each ticket item added to a ticket, so for example 10,20,30,40,ECT.
I also need the sequence number to reset for each ticket.  So every time a ticket item was added to a new ticket it would start at 10.  If a ticket items is deleted from the ticket the seq number does not change it stays the same for that ticket.

 
Here is how I kind of think the code should work.
 
On the object FX5__Ticket__c I have created a field called Starting _number__c it will default to zero on ever record created in FX5__Ticket__c
 
So I am going to write a trigger on the FX5__Ticket_Item__C that will fire after insert so I have a Record ID.
 
Get List of new records created in FX5__Ticket__c “ I think I can use trigger.new for this”
 
Now I need to somehow getting the starting number on the related FX5__Ticket__c record.
 
Then I need to do a FOR LOOP I think on all the records in Trigger.new
 
I need to get the Starting_Sequence_Number__c on FX5_Ticket_Item_C record that is related to FX5_Ticket_Item__C and +10 for each record writing it to SAP_Sequence_Number__c.
 
Then once all the related records have been update I need to take the count and update Starting_Sequence_Number__c on FX5_Ticket_Item_C with the value.
 
Any help would be great.
 
 
 
 
 
 
 
Grace Patiño PérezGrace Patiño Pérez
Hi Jeremy, 
Why don't you use that field to keep the next value (or the previous one)? then in the tigger you put the code in the ticket item object and update the value in the field in the ticket object. that way you don't need t count.

I hope this idea will help you.
Harish RamachandruniHarish Ramachandruni
Hi,


U can add rolle up summery filed on parent count of chield records .

assume  If now it's having 1 chield . u can add +1 = (ans )*sequencenumber like 10 .


every cheld u can add serice stating like 

chield :

Name         ticketnumber   strting sreies get form ticketnumber    first 2 numbers 
a -                10346                 10
b -                20346                20
c -                30346                30

parent :

create roll up summery maximum .

name          lastseries 

hyd              30




now u can write trigger on chield to get last series from parent which your selectd .

Add sries +10 to get value 

d-                40346                40




Rewgards ,
Harish.R.
Jeremy KJeremy K
I need to replace the value of the integer sum with the value of Starting_Sequence_Number__c from the parent run the for loop then take the new value of sum and update the value of Starting_Sequence_Number__c back to the parent.
I have seen code like this to pull info from a parent just not sure how to assign it to a integer. "List List = [SELECT Name, Id FROM ChildRecord WHERE ParentObject__c IN : trigger.newMap.keySet();"
 
trigger SAP_Seq_Number on FX5__Ticket_Item__c (Before insert) {



integer sum = 10;

for(integer i= 0;i<Trigger.new.size();i++){
    sum = i *10;         
    Trigger.new[i].SAP_Sequence_Number__c = sum;
}
}