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
bryan.revelant1.37773959363043bryan.revelant1.37773959363043 

APEX IF condition

X is a object that has a lookup to itself. X object is also master object to Y. Z is a master of Y. Y is a cross object of X and Z if a new X is created then the user has choice to make the new X a child of a pre existing X If they make the new X a child of a pre existing X, I want to find the parent X in Y then insert the child Xid and any Z values assocaited. Below is what I tried and where I am stuck

 

 

public with sharing class NewClassSiteAudit {

     

public void MyMethod6(list<X__c > PastAudit){     

list<Y__c > Objects2Update = new list< Y__c>();  //creating a container to house the Y__c records that I want to update or insert.    Set<Id> PastXID = new Set<Id>(); //this is container to house ids from Parent ID (PastA) so we can use in query   for(X__c SA : PastA)

{    

PastXID.add(SA.X__c);

}

 

for (Y__c LSTA: [Select id, Z__c , X__c       

       From Y__c  Where X__c in : PastXID ]){ //SOQL is getting all the X parent id's located in Y              

  //Part I am Stuck - what I want.  If the parent ID is within this Y then insert child X and Z values.    

if(  LSTA.X__c  = PastA.get(LSTA.PastXID))  insert  Objects2Update;                                 

  }     

  insert  Objects2Update;        

}         

}

gbu.varungbu.varun

Hi There is error

if(  LSTA.X__c  = PastA.get(LSTA.PastXID))  insert  Objects2Update;                                

 

USE double equal sign (==)

if(  LSTA.X__c = = PastA.get(LSTA.PastXID))  insert  Objects2Update;