You need to sign in to do that
Don't have an account?

System.NullPointerException: Script-thrown exception
Hi,
I'm trying to create a trigger which updates the Account owner based on the detail object criteria. The account assignment should be in a round robin fashion so that accounts will be distributed equally.
However, I get this error upon editing the detail object:
System.NullPointerException: Script-thrown exception
Below is my code:
trigger AssignNewClient on Master_Tracker__c (before insert) {
List<Id> AccountId = new list <id>();
for(Master_Tracker__c mt: Trigger.new)
{
if((mt.Product_Code__c == 'Advisory Services')
&&(mt.Agreement_Signed_Date__c != null)
&&(mt.Date_Payment_Info_Received__c != null)
&&(mt.Renewal__c = false)){
AccountId.add(mt.Account_Name__c);
}
{
Integer x = Integer.valueof(mt.Date_Payment_Info_Received__c);
Integer y = math.mod(x, 5);
Account a = new Account();
if(y == 0)
{
//When Mod = O update the owner to User 1 ID 005d0000001mr2u
//new org ID 005d0000001mr2u
a.OwnerId = '005d0000001mr2u';
}
else if(y == 1)
{
//When Mod = 2 update the owner to User 2 ID 005d0000001nHMY
a.OwnerId = '005d0000001nHMY';
}
else if(y == 2)
{
//When Mod = 3 update the owner to User 3 ID 005d0000002KBv1
a.OwnerId = '005d0000002KBv1';
}
else if(y == 3)
{
//When Mod = 4 update the owner to User 4 ID 005d0000001mr1u
a.OwnerId = '005d0000001mr1u';
}
else if(y == 4)
{
//When Mod = 5 update the owner to User 5 ID 005d0000002LDuq
a.OwnerId = '005d0000002LDuq';
}
}
}
}
I'm trying to create a trigger which updates the Account owner based on the detail object criteria. The account assignment should be in a round robin fashion so that accounts will be distributed equally.
However, I get this error upon editing the detail object:
System.NullPointerException: Script-thrown exception
Below is my code:
trigger AssignNewClient on Master_Tracker__c (before insert) {
List<Id> AccountId = new list <id>();
for(Master_Tracker__c mt: Trigger.new)
{
if((mt.Product_Code__c == 'Advisory Services')
&&(mt.Agreement_Signed_Date__c != null)
&&(mt.Date_Payment_Info_Received__c != null)
&&(mt.Renewal__c = false)){
AccountId.add(mt.Account_Name__c);
}
{
Integer x = Integer.valueof(mt.Date_Payment_Info_Received__c);
Integer y = math.mod(x, 5);
Account a = new Account();
if(y == 0)
{
//When Mod = O update the owner to User 1 ID 005d0000001mr2u
//new org ID 005d0000001mr2u
a.OwnerId = '005d0000001mr2u';
}
else if(y == 1)
{
//When Mod = 2 update the owner to User 2 ID 005d0000001nHMY
a.OwnerId = '005d0000001nHMY';
}
else if(y == 2)
{
//When Mod = 3 update the owner to User 3 ID 005d0000002KBv1
a.OwnerId = '005d0000002KBv1';
}
else if(y == 3)
{
//When Mod = 4 update the owner to User 4 ID 005d0000001mr1u
a.OwnerId = '005d0000001mr1u';
}
else if(y == 4)
{
//When Mod = 5 update the owner to User 5 ID 005d0000002LDuq
a.OwnerId = '005d0000002LDuq';
}
}
}
}
mt.Product_Code__c may be put a null cehck to this so code will be . Similarly if error comes again put check to other fields accessed in the code. If you still see the issue then share the error message.
trigger AssignNewClient on Master_Tracker__c (before insert) {
Map<Id,Account> updatedowner = new Map<Id,Account>();
List<Id> AccountIds = new list <id>();
for(Master_Tracker__c mt: Trigger.new)
{
if((mt.Product_Code__c == 'Advisory Services')
&&(mt.Agreement_Signed_Date__c != null)
&&(mt.Date_Payment_Info_Received__c != null)
&&(mt.Renewal__c = false)){
AccountIds.add(mt.Account_Name__c);
}
updatedowner = new Map<Id,Account>([SELECT id,Name FROM Account WHERE ID IN :AccountIds]);
{
Integer x = Integer.valueof(mt.BID__c);
Integer y = math.mod(x, 5);
Account a = new Account();
if(y == 0)
{
//When Mod = O update the owner to User 1 ID 005d0000001mr2u
//new org ID 005d0000001mr2u
a.OwnerId = '005d0000001mr2u';
}
else if(y == 1)
{
//When Mod = 2 update the owner to User 2 ID 005d0000001nHMY
a.OwnerId = '005d0000001nHMY';
}
else if(y == 2)
{
//When Mod = 3 update the owner to User 3 ID 005d0000002KBv1
a.OwnerId = '005d0000002KBv1';
}
else if(y == 3)
{
//When Mod = 4 update the owner to User 4 ID 005d0000001mr1u
a.OwnerId = '005d0000001mr1u';
}
else if(y == 4)
{
//When Mod = 5 update the owner to User 5 ID 005d0000002LDuq
a.OwnerId = '005d0000002LDuq';
}
update updatedowner.values();
}
}
}