You need to sign in to do that
Don't have an account?
SFDC 18
Update a field with count using apex classs
Hi,
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.
I'm stuck with the if clause part. Can anyone help me with this?
Name is a field on zone object with picklist values of zone
On No of Agents field,
it should show the count of agents in that zone
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.
I'm stuck with the if clause part. Can anyone help me with this?
Name is a field on zone object with picklist values of zone
On No of Agents field,
public class NoofAgents { List<Zone> zonestoupdate = [SELECT Id,Zones__C FROM Agent__C]; for(Zone z:zonestoupdate) { Integer NoofAgents = [SELECT count() FROM Agent__C WHERE Zones__C == North]; if (Name__c == North) { } } }
it should show the count of agents in that zone
This Code will update for all the zones.
Choose this as best answer if you like.
Regards,
Bala
All Answers
Regards,
Bala
I got compile errors like variable doesn't exist when i have executed the code
Try this for North. but for other regions will post you simplified code after some time. You can write if for south as well but let us try to automate.
Regards,
Bala
Regards,
Sai
This Code will update for all the zones.
Choose this as best answer if you like.
Regards,
Bala
I frequently face this kind of errors in my code
In the previoue error "variable doesn't exist: z error" because we declared a variable in for loop and upsert out side the loop. once i moved inside the its solved.
when ever you use a variable it is declared with in the code block or if you use public the you can access any where in the code.
For example if you give integer a; by defaule its private and you can not use it out side the code block {} of out side the method.
Regards,
Poojitha