You need to sign in to do that
Don't have an account?
Nathan Prats 22
Limit Usage for NS
Hello,
I have this code :
but each time i run it, i have a Limit Usage for NS error.
10:45:16:000 LIMIT_USAGE_FOR_NS Maximum CPU time: 15118 out of 10000 ******* CLOSE TO LIMIT
What can be wrong ?
I have this code :
List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE]; Integer X = [SELECT Count() FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE]; do { for(Account Acc : AccList){ Acc.OwnerId = Acc.Parent.OwnerId; } } while (X > 0); update AccList;
but each time i run it, i have a Limit Usage for NS error.
10:45:16:000 LIMIT_USAGE_FOR_NS Maximum CPU time: 15118 out of 10000 ******* CLOSE TO LIMIT
What can be wrong ?
You are not changing the value of X ain your code. You can use IF condition if you want to run on the basis of value of X .
I want the code to run as long as the query X > 0.
I guess I created an infinite loop as the query is run only one time ?
How can I run the code till the query X = 0 ?
Yes this creates an infinite loop as the value of X is not changing/decreasing. As the query is run once, it gives the value of X which is never changing in the code and using query in loops is not good as it can hit the limits.
Can you please tell me how your value of X is changing ..??
Sure, this code it supposed to reassign all accounts to the right owner.
It uses the account hierarchy. The Account_Owner_Parent_Owner__c formula field tests if the account owner is different from the parent account owner.
X is basically the number of accounts where the owner is different from the parent account owner.
If I run the code only 1 time, it will reassign 1 node in the account hierarchy. That's why I'm trying to execute the code until X = 0.
List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId
FROM Account
WHERE Account_Owner_Parent_Owner__c = TRUE
AND IsExcludedFromRealign = FALSE];
if(AccList.size() > 0)
{
for(Account Acc : AccList){
Acc.OwnerId = Acc.Parent.OwnerId;
}
update AccList
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj.
Your code just reassign 1 node in the account hierarchy.
The following code reassigns 3 nodes. I might just go with this
Try if this helps.!!