You need to sign in to do that
Don't have an account?
sekhar 131
Visualforce Error :Attempt to de-reference a null object
Visualforce Error :Attempt to de-reference a null object
line no in 27 apex page
Can any one help me out with this Error .I'm getting
my Task- I want a customized report on Lead owners and their Activities count.
code
class
public class ActiveHistoryClass
{
public list<wrapper> wrap{set;get;}
public set<id> setr1{get;set;}
public map<string,list<wrapper>> ma {set;get;}
public AggregateResult[] numTasks{set;get;}
public List<User> userinfo{get;set;}
public ActiveHistoryClass()
{
userinfo=[select id,name from User];
setr1=new set<Id>();
for(User usr:userinfo)
{
setr1.add(usr.id);
}
numTasks =[select Owner.name owner,Status sta,Activity_type__c active,count(id) coun from Task GROUP BY Owner.name,Status,Activity_type__c];
wrap = new List<wrapper>();
System.debug('The Aggregate value is'+numTasks);
for(AggregateResult ar:numTasks)
{
// wrap.add(new wrapper(ar.get('owner')),(ar.get('sta')),(ar.get('active')),(ar.get('coun')));
wrap.add(new wrapper(ar));
system.debug('wrap'+wrap);
ma.put((string)ar.get('owner'),wrap);
// system.debug('ma'+ar);
setr1.add(ar.id);
system.debug('setr1'+ar.Id);
}
System.debug('The map value is'+ma);
}
public class wrapper {
public integer coun{get;set;}
public String owner{get;set;}
public String sta{get;set;}
public String active{get;set;}
public string oname{set;get;}
public wrapper(AggregateResult ar)
{
owner = (String) ar.get('owner');
sta = (String) ar.get('sta');
active = (String) ar.get('active');
coun=(integer) ar.get('coun');
this.oname=owner;
}
}
}
vf page
<apex:page controller="ActiveHistoryClass" >
<style>
table {
font-family: arial, sans-serif; border-collapse: collapse; width: 100%;padding: 10px;
}
td, th {
border: 1px solid #dddddd;text-align: left;padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<apex:form >
<apex:pageBlock >
<!--- <apex:pageBlockTable>---->
<body>
<table>
<thead>
<tr>
<th>Lead.name</th>
<th>Status</th>
<th>Ativity Type</th>
<th>Count</th>
</tr>
</thead>
<apex:repeat value="{!setr1}" var="ownerids">
<!---<tr>
<td>{!ownerids.owner}</td>
<td>{!ownerids.sta}</td>
<td>{!ownerids.active}</td>
<td>{!ownerids.coun}</td>
</tr> --->
<apex:repeat value="{!ma[ownerids]}" var="c">
<tbody>
<tr>
<td>{!c.owner}</td>
<td>{!c.sta}</td>
<td>{!c.active}</td>
<td>{!c.coun}</td>
</tr>
</tbody>
<!---<apex:column value="{!c.o}" headerValue="Lead.name" styleClass="padding: 13px;" style="font-family: arial, sans-serif; border-collapse: collapse; width: 30%;padding: 10px"/>
<apex:column value="{!c.s}" headerValue="Status"/>
<apex:column value="{!c.a}" headerValue="Ativity Type"/>
<apex:column value="{!c.ct}" headerValue="Count"/>---->
</apex:repeat>
</apex:repeat>
</table>
</body>
</apex:pageBlock>
</apex:form>
</apex:page>
please help me
line no in 27 apex page
Can any one help me out with this Error .I'm getting
my Task- I want a customized report on Lead owners and their Activities count.
code
class
public class ActiveHistoryClass
{
public list<wrapper> wrap{set;get;}
public set<id> setr1{get;set;}
public map<string,list<wrapper>> ma {set;get;}
public AggregateResult[] numTasks{set;get;}
public List<User> userinfo{get;set;}
public ActiveHistoryClass()
{
userinfo=[select id,name from User];
setr1=new set<Id>();
for(User usr:userinfo)
{
setr1.add(usr.id);
}
numTasks =[select Owner.name owner,Status sta,Activity_type__c active,count(id) coun from Task GROUP BY Owner.name,Status,Activity_type__c];
wrap = new List<wrapper>();
System.debug('The Aggregate value is'+numTasks);
for(AggregateResult ar:numTasks)
{
// wrap.add(new wrapper(ar.get('owner')),(ar.get('sta')),(ar.get('active')),(ar.get('coun')));
wrap.add(new wrapper(ar));
system.debug('wrap'+wrap);
ma.put((string)ar.get('owner'),wrap);
// system.debug('ma'+ar);
setr1.add(ar.id);
system.debug('setr1'+ar.Id);
}
System.debug('The map value is'+ma);
}
public class wrapper {
public integer coun{get;set;}
public String owner{get;set;}
public String sta{get;set;}
public String active{get;set;}
public string oname{set;get;}
public wrapper(AggregateResult ar)
{
owner = (String) ar.get('owner');
sta = (String) ar.get('sta');
active = (String) ar.get('active');
coun=(integer) ar.get('coun');
this.oname=owner;
}
}
}
vf page
<apex:page controller="ActiveHistoryClass" >
<style>
table {
font-family: arial, sans-serif; border-collapse: collapse; width: 100%;padding: 10px;
}
td, th {
border: 1px solid #dddddd;text-align: left;padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<apex:form >
<apex:pageBlock >
<!--- <apex:pageBlockTable>---->
<body>
<table>
<thead>
<tr>
<th>Lead.name</th>
<th>Status</th>
<th>Ativity Type</th>
<th>Count</th>
</tr>
</thead>
<apex:repeat value="{!setr1}" var="ownerids">
<!---<tr>
<td>{!ownerids.owner}</td>
<td>{!ownerids.sta}</td>
<td>{!ownerids.active}</td>
<td>{!ownerids.coun}</td>
</tr> --->
<apex:repeat value="{!ma[ownerids]}" var="c">
<tbody>
<tr>
<td>{!c.owner}</td>
<td>{!c.sta}</td>
<td>{!c.active}</td>
<td>{!c.coun}</td>
</tr>
</tbody>
<!---<apex:column value="{!c.o}" headerValue="Lead.name" styleClass="padding: 13px;" style="font-family: arial, sans-serif; border-collapse: collapse; width: 30%;padding: 10px"/>
<apex:column value="{!c.s}" headerValue="Status"/>
<apex:column value="{!c.a}" headerValue="Ativity Type"/>
<apex:column value="{!c.ct}" headerValue="Count"/>---->
</apex:repeat>
</apex:repeat>
</table>
</body>
</apex:pageBlock>
</apex:form>
</apex:page>
please help me
Greetings to you!
You need to instantiate ma in the constructor as default value of ma is null. That's why you are getting this error.
Try this:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Another error in apex page
Map key 0057F000003VsteQAC not found in map
Error is in expression '{!ma[ownerids]}' in component <apex:repeat> in page samplevf
code
<apex:page controller="ActiveHistoryClass" >
<style>
table {
font-family: arial, sans-serif; border-collapse: collapse; width: 100%;padding: 10px;
}
td, th {
border: 1px solid #dddddd;text-align: left;padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<apex:form >
<apex:pageBlock >
<!--- <apex:pageBlockTable>---->
<body>
<table>
<thead>
<tr>
<th>Lead.name</th>
<th>Status</th>
<th>Ativity Type</th>
<th>Count</th>
</tr>
</thead>
<apex:repeat value="{!setr1}" var="ownerids">
<!---<tr>
<td>{!ownerids.owner}</td>
<td>{!ownerids.sta}</td>
<td>{!ownerids.active}</td>
<td>{!ownerids.coun}</td>
</tr> --->
<apex:repeat value="{!ma[ownerids]}" var="c">
<tbody>
<tr>
<td>{!c.owner}</td>
<td>{!c.sta}</td>
<td>{!c.active}</td>
<td>{!c.coun}</td>
</tr>
</tbody>
<!---<apex:column value="{!c.o}" headerValue="Lead.name" styleClass="padding: 13px;" style="font-family: arial, sans-serif; border-collapse: collapse; width: 30%;padding: 10px"/>
<apex:column value="{!c.s}" headerValue="Status"/>
<apex:column value="{!c.a}" headerValue="Ativity Type"/>
<apex:column value="{!c.ct}" headerValue="Count"/>---->
</apex:repeat>
</apex:repeat>
</table>
</body>
</apex:pageBlock>
</apex:form>
</apex:page>
Visualforce:
Controller:
Refer: https://salesforce.stackexchange.com/questions/15748/can-we-check-if-a-key-exists-in-a-map-in-vf-page
Regards,
Khan Anas