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
ziedzied 

Split one object into two(parent-child relationship)

Hi everyone,

I have data coming to a salesforce object from a third party tool like this:

ID  |  field1  | field2 | criteria1importance  |  criteria1score  |  criteria1competitorscore | criteria2importance  |  criteria2score  |  criteria2competitorscore

i want to split this in a parent child relationship like this :


parent object :

ID  |  field1  | field2 |  criteria(foreign key)

and child object :

criteriaName  | importance  | score  | competitorScore

hope that makes sence, i have been searching for this since 2 weeks :/
Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
ziedzied

Problem solved, i have created the child object and an apex trigger to fill the fields. this is how it looks like:

trigger ResultChildTrigger on VANG_Survey_Result__c (after insert) {
List<SurveyDetail__c> details = new List<SurveyDetail__c>();
for (VANG_Survey_Result__c newResult: Trigger.New) {
    
        details.add(new SurveyDetail__c(
        Name = 'Overall Sales Approach',
        Survey_Result__c = newResult.Id,
        importance__c = decimal.valueOf(newResult.Q1Value__c),
        score__c = decimal.valueOf(newResult.Q2Value__c),
        competitor_score__c = decimal.valueOf(newResult.Q3Value__c)
        ));  
   }
insert details;

}