Skip to main content
Known Participant
May 15, 2024 2:34 AM UTC
Solved

How can I cast nested CDTs to recordtype with relationships?

I have some nested CDTs, like a nested in b, b nested in c, I want to cast it to recordtype with relationship, like C has one-to-many relationship to B, B has one-to-many relationship to A. All fields are mapped, how can I cast?

    shubhama926776
    Brainy
    May 15, 2024 5:20 AM UTC

    Define matching record types (A, B, C) for your CDTs.
    Use nested loops to iterate through C then B.
    Inside loops, extract data from CDTs and assign to record types.
    If your record types have list fields designed to hold related records (e.g: record_C.related_B), directly add the created records (e.g., record_B)

    शुभम्

    4 replies

    karthikk538
    Inspiring
    May 15, 2024 3:16 AM UTC

    One  way to do this is create a structure with recordtType!recordName(key :vallue), and map the nested cdt values to the record type.

    shubhama926776
    Brainy
    May 15, 2024 5:20 AM UTC

    Define matching record types (A, B, C) for your CDTs.
    Use nested loops to iterate through C then B.
    Inside loops, extract data from CDTs and assign to record types.
    If your record types have list fields designed to hold related records (e.g: record_C.related_B), directly add the created records (e.g., record_B)

    शुभम्
    Known Participant
    May 15, 2024 5:31 AM UTC

    Thank you, it works

    peter.lewis
    Employee
    May 15, 2024 2:12 PM UTC

    Assuming you have the same names for your fields, then you just cast it and it should work - here's an example:

    If you don't have the same field names, then you may need to do some massaging of the data to get it in the right format like others have mentioned.