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
Jay Parikh 36Jay Parikh 36 

variable not exist

trigger calcyforsas on Location_Cal__c (after insert , after update ) { 
    set<id> tst = new set <id>();
    
    if(trigger.isinsert || trigger.isupdate){
        for(Location_Cal__c ls : trigger.new ) {
            if(ls.testeTop_X_Designation__c != null){
               tst.add(ls.testeTop_X_Designation__c);
               system.debug('-----55'+tst);
            }
        } 
        for (testeTop_X_Designation__c ty :[select id ,Hello__c from testeTop_X_Designation__c where id in : tst  ]){
            system.debug('------88'+ty.Hello__c);
            string fx = ty.Hello__c;
            system.debug('-----55'+fx);
            Location_Cal__c cj = new Location_Cal__c();
            cj.Id = ls.id;
            cj.sas__c = fx;
            update cj;
            }
         
       }
}

 
Best Answer chosen by Jay Parikh 36
HARSHIL U PARIKHHARSHIL U PARIKH
Here we go..
 
Trigger calcyforsas on testeTop_X_Designation__c(after insert , after update ) 
{ 
   List<Location_Cal__c> childFinalList = New List<Location_Cal__c>();
   
   If(Trigger.IsInsert || Trigger.IsUpdate)
   {
       For(testeTop_X_Designation__c Parent : Trigger.New)
       {
           If(Parent.Hello__c != null)
           {
              List<Location_Cal__c> allChilds = [Select Id, sas__c FROM Location_Cal__c WHERE testeTop_X_Designation__c =:Parent.Id];
              
              If(allChilds.size() > 0)
              {
                  
                  for(Location_Cal__c EveryChild : allChilds)
                  {
                      EveryChild.sas__c = Parent.Hello__c;
                      childFinalList.add(EveryChild );
                  }
              }
           }
       }
   }
   try{
       If(!childFinalList.IsEmpty()){
           update childFinalList;
       }
   }
   Catch(Exception e){
       System.debug('Thrown error for calcyforsas Trigger Is:: ' + e.getMessage());
   }
}

If it solves the query then please mark it as best answer!
 

All Answers

HARSHIL U PARIKHHARSHIL U PARIKH
Wait.. whats the requirements here though?

This is what the picture sets in mind right now:

Parent obj : testeTop_X_Designation__c
           Fields: Id, Hello__c

Child Obj: Location_Cal__c
          Fields: testeTop_X_Designation__c, sas__c

Are you trying to update Hello__c as a sas__c? Means whenever there is child record with value in sas__c field then parent should be updated as the same value in Hello__c field. Let us know.
Jay Parikh 36Jay Parikh 36
Hi Req is when Hello field has value it will take and update sas field which is on Location Object and Test is parent and Location is child object
HARSHIL U PARIKHHARSHIL U PARIKH
Why don't you just make a formula for it then.
 sas__c = testeTop_X_Designation__r.Hello__c
Jay Parikh 36Jay Parikh 36
I want to achieve it by trigger 
HARSHIL U PARIKHHARSHIL U PARIKH
Here we go..
 
Trigger calcyforsas on testeTop_X_Designation__c(after insert , after update ) 
{ 
   List<Location_Cal__c> childFinalList = New List<Location_Cal__c>();
   
   If(Trigger.IsInsert || Trigger.IsUpdate)
   {
       For(testeTop_X_Designation__c Parent : Trigger.New)
       {
           If(Parent.Hello__c != null)
           {
              List<Location_Cal__c> allChilds = [Select Id, sas__c FROM Location_Cal__c WHERE testeTop_X_Designation__c =:Parent.Id];
              
              If(allChilds.size() > 0)
              {
                  
                  for(Location_Cal__c EveryChild : allChilds)
                  {
                      EveryChild.sas__c = Parent.Hello__c;
                      childFinalList.add(EveryChild );
                  }
              }
           }
       }
   }
   try{
       If(!childFinalList.IsEmpty()){
           update childFinalList;
       }
   }
   Catch(Exception e){
       System.debug('Thrown error for calcyforsas Trigger Is:: ' + e.getMessage());
   }
}

If it solves the query then please mark it as best answer!
 
This was selected as the best answer