Skip to main content
I have all participant and states object (two records registered and assessed ). for some participant is not assesed inthe table evethough it is actually assessed. need to insert those records to states as assesesd 

i have list of patticipant ids and list of  states as assessed 

 if(recs.size()>0 && participantsatates.size()>0) 

         {

              for(participant__c p:recs)

                 {

             

                     for(States__c pstate :participantsatates)

                         

                         {

                            IF (P.Id = pstate.Participant__c)

                            {

                                

                                

                            }

                             

                 

                         }

                 }
10 respuestas
  1. 24 oct 2017, 08:36
    Hi Sasham,

    Try this,

     

    //Storing all the State with Assessd picklist value in Set type

    Set<id> PartSet = new Set<id>();

    For(State__c st : [Select id,states,Participantt_c from State__c where Participantt_c != null]){

    if(st.states == 'assesesd')

    PartSet.add(st.Participantt_c);

    }

    //Checking participant have State as Assessed picklist value or not

    List<State__c> insertList = new List<State__c>();

    For(Participantt_c pt : [Select id from Participantt_c]){

    if(!PartSet.contains(pt.id))

    State__c stObj = new State__c();

    stObj.Participantt_c = pt.id;

      stObj.states = 'assesesd';

    insertList.add(stObj);

    }

    //Insert state records

    if(insertList.size() > 0)

    insert insertList;

    Thanks,

    If it helps you, please mark is as best answer, so it will be helpful for other developers.
0/9000