You need to sign in to do that
Don't have an account?
Getting Error- execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject:
Hi Expert,
iam getting error when executing the trigger.
scenerio- update the field " project risk count" of child object "Project Portfolio" with the field "risk count" of parent object "Project".
Class-
public class updateProjectRiskCount
{
public static List<CloudbyzITPM__Project__c> affectedRiskCount = new List<CloudbyzITPM__Project__c>();
public static set<ID> affc = new set<ID>();
public static void processAfterUpdateRiskCount()
{
affectedRiskCount = (List<CloudbyzITPM__Project__c>)Trigger.New;
if(affectedRiskCount.size()>0){
for(CloudbyzITPM__Project__c affc1 : affectedRiskCount)
{
affc.add(affc1.id);
}
}
CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Project_Risk_Count__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
list<CloudbyzITPM__Project__c> affectedRiskCount1 = [select id, name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Risk_Count__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
Decimal i=0;
if(affectedRiskCount1.size()>0)
{
for(CloudbyzITPM__Project__C afc1 : affectedRiskCount1)
{
i = i + afc1.CloudbyzITPM__Risk_Count__c;
}
}
if(i>0)
{
System.debug('@@pBUFinal@@');
fn.CloudbyzITPM__Project_Risk_Count__c = i;
}
update fn;
System.debug('@@fn4@@'+fn);
}
}
Trigger-
Trigger UpdateRC2 on CloudbyzITPM__Project__c (before insert, before update, before delete, after insert, after update, after delete)
{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)
{
updateProjectRiskCount.processAfterUpdateRiskCount();
}
}
Note- i have written 4 triggers on the same object "project".
Screenshot attached.

iam getting error when executing the trigger.
scenerio- update the field " project risk count" of child object "Project Portfolio" with the field "risk count" of parent object "Project".
Class-
public class updateProjectRiskCount
{
public static List<CloudbyzITPM__Project__c> affectedRiskCount = new List<CloudbyzITPM__Project__c>();
public static set<ID> affc = new set<ID>();
public static void processAfterUpdateRiskCount()
{
affectedRiskCount = (List<CloudbyzITPM__Project__c>)Trigger.New;
if(affectedRiskCount.size()>0){
for(CloudbyzITPM__Project__c affc1 : affectedRiskCount)
{
affc.add(affc1.id);
}
}
CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Project_Risk_Count__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
list<CloudbyzITPM__Project__c> affectedRiskCount1 = [select id, name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Risk_Count__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
Decimal i=0;
if(affectedRiskCount1.size()>0)
{
for(CloudbyzITPM__Project__C afc1 : affectedRiskCount1)
{
i = i + afc1.CloudbyzITPM__Risk_Count__c;
}
}
if(i>0)
{
System.debug('@@pBUFinal@@');
fn.CloudbyzITPM__Project_Risk_Count__c = i;
}
update fn;
System.debug('@@fn4@@'+fn);
}
}
Trigger-
Trigger UpdateRC2 on CloudbyzITPM__Project__c (before insert, before update, before delete, after insert, after update, after delete)
{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)
{
updateProjectRiskCount.processAfterUpdateRiskCount();
}
}
Note- i have written 4 triggers on the same object "project".
Screenshot attached.
Below updated updateProjectRiskCount apex class should help you.
Thanks for replying,
i have executed the above code, but now it is giving error- execution of AfterUpdate caused by: System.NullPointerException: Argument cannot be null.
field which iam updating is of number type "Project Risk Count".
error screenshot-
Its now giving error in compile time that - Invalid field CloudbyzITPM__Project_Risk_Count__c for SObject CloudbyzITPM__Project__c
Regards,
Deepak
Again it is showing same error and one more :(
variable does not exist: fn
I think its system.debug statement at line no 41
try this once
Let us know if you have any issues.
Thanks.
i have a similar scenerio in which i have to update the field "budget hours" of "project portfolio" object with the "budget hour" field of "project" object, hence 1 "project portfolio" have multiple "project", it should have all the sum of "budget hour" field into that "budget hours" of "project portfolio" object.
But when we cange the "project portfolio" in "project" object. so in the "budget hours" field of "project portfolio" should deacreases, coz we have change the "project portfolio" of that partcular "project" and add the "budget hours" of another "project portfolio". but it is not hapenning in my org.
Code is here-
public class updateBudgetedHours
{
public static List<CloudbyzITPM__Project__c> affectedBudgetedHours = new List<CloudbyzITPM__Project__c>();
public static set<ID> affc = new set<ID>();
public static void processAfterUpdateBudgetedHours()
{
affectedBudgetedHours = (List<CloudbyzITPM__Project__c>)Trigger.New;
if(affectedBudgetedHours.size()>0){
for(CloudbyzITPM__Project__c affc1 : affectedBudgetedHours)
{
if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
{
affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
}
}
if(affc.size()>0)
{
CloudbyzITPM__Project_Portfolio__c fn = [select id,name, CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project_Portfolio__c where id IN :affc limit 1];
list<CloudbyzITPM__Project__c> affectedBudgetedHours1 = [select id,name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
Decimal i=0;
if(affectedBudgetedHours1.size()>0)
{
for(CloudbyzITPM__Project__C afc1 : affectedBudgetedHours1)
{
i = i + afc1.CloudbyzITPM__Budgeted_Hours__c;
}
}
if(i>0)
{
System.debug('@@pBUFinal@@');
fn.CloudbyzITPM__Budgeted_Hours__c = i;
}
update fn;
System.debug('@@fn4@@'+fn);
}
}
}
}
Trigger-
Trigger UpdateBH on CloudbyzITPM__Project__c (before insert, before update, before delete,after insert, after update, after delete)
{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter )
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}
if((Trigger.isDelete || Trigger.isUpdate) && Trigger.isBefore)
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}
}
what to change in the code?
Thanks & Regards,
Deepak
Below code should help you.