Salesforce Asked by Phuc on October 4, 2021
I have a class where i am trying to update 2 lookup fields if they exist. I keep getting an error where it states the fields do not exist. Is my for loop incorrect?
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;
}
}
}
You are attempting to access variables on a list, rather than a single sObject.
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
}
}
newaction1
is a List<Action_Item__c> newaction1
. You seem to be going for act1.Project_ID__c
.
Correct answer by David Reed on October 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP