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
Phuc Nguyen 18Phuc Nguyen 18 

Apex Update lookup class issue. Variable does not exist

Trying to populate lookup Planning_Application__c and Project_ID but getting erro Variable does not exist at newpl.Planning_Application__c and newproj.Project_ID__c
public set<id> planId = new Set<id>();
public set<id> projId = new Set<id>();
public list<Action_Item__c> pl;
public list<Action_Item__c> pj;
public list<Project__c> lu;
public list<Planning_Application__c> lu2;


public void initialize(String sObjectName) {
        if (!Trigger.isDelete) {
            for (SObject ids : Trigger.new) {
                Action_Item__c action = (Action_Item__c) ids;
                if (action.Planning_Application__c != null) {
                    planId.add(action.Planning_Application__c);
                }
                if (action.Project_ID__c != null) {
                    projId.add(action.Project_ID__c);
                }
            }
        }
    }

 public void bulkAfter() {
        if (!Trigger.isDelete) {
            if (Trigger.isInsert) {
                lu = [
                    SELECT
                        Id,
                        Name
                    FROM Project__c
                    WHERE id IN :projId
                ];
            }
        }
        if (!Trigger.isDelete) {
            if (Trigger.isInsert) {
                lu2 = [
                    SELECT
                        Id,
                        Name
                        FROM Planning_Application__c
                    WHERE id IN :planId
                ];
            }
        }

    }


 public void afterInsert(SObject so) {
    List<Project__c> newproject = lu;
    List<Planning_Application__c> newaplan = lu2;

    For(Project__c newproj : newproject){
    for (Action_Item__c act1 : newproj.Action_Items__r)
    {
        if (newproj.Project_ID__c != null) {
            act1.Project_ID__c = newproj.Project_ID__c;
        }
    }
    }
    
    For(Planning_Application__c newpl : newplan){
            for (Action_Item__c act2 : newpl.Actions__r)
        {
            act2.Planning_Application__c = newpl.Planning_Application__c;
        }
    }
    }

 
Best Answer chosen by Phuc Nguyen 18
SwethaSwetha (Salesforce Developers) 
HI Phuc,
I see that your query has been already answered in https://salesforce.stackexchange.com/questions/313337/class-to-update-lookup-failing
 
for (Action_Item__c act1 : newaction1)
    {
        if (newaction1.Project_ID__c != null) {  --- does not exist
            act1.Project_ID__c = newaction1.Project_ID__c;  --- does not exist
        }
    }
Please mark this answer as best so that others facing the same issue will find this information useful. Thank you