You need to sign in to do that
Don't have an account?
m 10
Argument cannot be null. An unexpected error has occurred. Your development organization has been notified.
when i am running below vf page code i am getting error message ,in apex class i am getting response but i am not able to insert values dynamically into the object in class line no 21 it's throing an error
note:Argument cannot be null.
An unexpected error has occurred. Your development organization has been notified.
class:
global class SampleReport {
public String body{set;get;}
public list<integer> mylist{set;get;}
public List<ReportFields> consolewrapperlist{get;set;}
public SampleReport(){
Httprequest req=new Httprequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string url='https://canvasjs.com/data/gallery/javascript/daily-sales-data.json';
req.setEndpoint(url);
req.setHeader('Content-type','application/json');
req.setMethod('GET');
res = http.send(req);
system.debug('=========res>>>'+res);
consolewrapperlist=new List<ReportFields>();
if(res.getstatusCode() == 200 && res.getbody() != null){
string body=res.getbody().replaceAll('\n','').replaceAll('\r','');
system.debug('==========>>>body....>'+body);
System.JSONParser jp=json.createParser(res.getbody());
system.debug('==.>>>jp'+jp);
while (jp.nextToken() != null) {
// find the stock part of the response
if (jp.getCurrentToken() == JSONToken.START_OBJECT) {
// parse the stock response and form the response for this controller
ReportFields responseObject = (ReportFields)jp.readValueAs(ReportFields.class);
Daily_sales_Data__c sd=new Daily_sales_Data__c();
sd.date__c=Date.valueOf(responseObject.dates);
sd.units__c=Integer.valueOf(responseObject.units);
insert sd;
system.debug('Hello There ' +sd);
// return the serialized response
//return JSON.serialize(new PackagedReturnItem(returnItems));
consolewrapperlist.add(responseObject);
system.debug('Hello There ' +consolewrapperlist);
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Data not find');
ApexPages.addMessage(myMsg);
}
}
public class ReportFields
{
public String dates;
public string units;
public ReportFields(String dates, String units) {
this.dates = dates;
this.units = units;
}
}
}
Vf page:
<apex:page controller="SampleReport">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!consolewrapperlist}" var="wrap" width="100%">
<apex:column headerValue="date" value="{!wrap.rdate}"/>
<apex:column headerValue="units" value="{!wrap.runits}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
note:Argument cannot be null.
An unexpected error has occurred. Your development organization has been notified.
class:
global class SampleReport {
public String body{set;get;}
public list<integer> mylist{set;get;}
public List<ReportFields> consolewrapperlist{get;set;}
public SampleReport(){
Httprequest req=new Httprequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string url='https://canvasjs.com/data/gallery/javascript/daily-sales-data.json';
req.setEndpoint(url);
req.setHeader('Content-type','application/json');
req.setMethod('GET');
res = http.send(req);
system.debug('=========res>>>'+res);
consolewrapperlist=new List<ReportFields>();
if(res.getstatusCode() == 200 && res.getbody() != null){
string body=res.getbody().replaceAll('\n','').replaceAll('\r','');
system.debug('==========>>>body....>'+body);
System.JSONParser jp=json.createParser(res.getbody());
system.debug('==.>>>jp'+jp);
while (jp.nextToken() != null) {
// find the stock part of the response
if (jp.getCurrentToken() == JSONToken.START_OBJECT) {
// parse the stock response and form the response for this controller
ReportFields responseObject = (ReportFields)jp.readValueAs(ReportFields.class);
Daily_sales_Data__c sd=new Daily_sales_Data__c();
sd.date__c=Date.valueOf(responseObject.dates);
sd.units__c=Integer.valueOf(responseObject.units);
insert sd;
system.debug('Hello There ' +sd);
// return the serialized response
//return JSON.serialize(new PackagedReturnItem(returnItems));
consolewrapperlist.add(responseObject);
system.debug('Hello There ' +consolewrapperlist);
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Data not find');
ApexPages.addMessage(myMsg);
}
}
public class ReportFields
{
public String dates;
public string units;
public ReportFields(String dates, String units) {
this.dates = dates;
this.units = units;
}
}
}
Vf page:
<apex:page controller="SampleReport">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!consolewrapperlist}" var="wrap" width="100%">
<apex:column headerValue="date" value="{!wrap.rdate}"/>
<apex:column headerValue="units" value="{!wrap.runits}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please change your class like below:
Apex Class :
global class SampleReport {
public String body{set;get;}
public list<integer> mylist{set;get;}
public List<ReportFields> consolewrapperlist{get;set;}
public SampleReport(){
Httprequest req=new Httprequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string url='https://canvasjs.com/data/gallery/javascript/daily-sales-data.json';
req.setEndpoint(url);
req.setHeader('Content-type','application/json');
req.setMethod('GET');
res = http.send(req);
system.debug('=========res>>>'+res);
consolewrapperlist=new List<ReportFields>();
if(res.getstatusCode() == 200 && res.getbody() != null){
string body=res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('date','dates');
system.debug('==========>>>body....>'+body);
System.JSONParser jp=json.createParser(res.getbody());
system.debug('==.>>>jp'+jp);
while (jp.nextToken() != null) {
// find the stock part of the response
if (jp.getCurrentToken() == JSONToken.START_OBJECT) {
List<ReportFields> responseObject = (List<ReportFields>)JSON.deserialize(body,List<ReportFields>.class);
system.debug('responseObject ==> ' + responseObject );
List<Daily_sales_Data__c> dailyList = new List<Daily_sales_Data__c>();
for(ReportFields rf : responseObject )
{
Datetime dt = datetime.newinstance(long.valueOf(rf.dates));
Date datevalue = dt.date();
system.debug( 'dt ==> ' + datevalue );
rf.dates = String.ValueOf(datevalue);
Daily_sales_Data__c sd=new Daily_sales_Data__c();
sd.date__c=datevalue;
sd.units__c=Integer.valueOf(rf.units);
dailyList.add(sd);
}
consolewrapperlist.addall(responseObject);
if(dailyList.size() > 0)
insert dailyList;
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Data not find');
ApexPages.addMessage(myMsg);
}
}
public class ReportFields
{
public string dates {get;set;}
public string units{get;set;}
}
}
VF Page :
<apex:page controller="SampleReport">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!consolewrapperlist}" var="wrap" width="100%">
<apex:column headerValue="date" value="{!wrap.dates}"/>
<apex:column headerValue="units" value="{!wrap.units}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Maharajan.C
I forget to mention that you are inserting the records(DML) in Constructor and it will not be allowed in Salesforce. To Overcome this you have to made the below changes in Class and VF Pages:
Surely the below changes will solve your issue.
1. Empty the Constructor.
2. Add the new method SampleReportload.
3. use the Action tag in apex:page action="{!SampleReportload}"
VF Page:
<apex:page controller="SampleReport" action="{!SampleReportload}">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!consolewrapperlist}" var="wrap" width="100%">
<apex:column headerValue="date" value="{!wrap.dates}"/>
<apex:column headerValue="units" value="{!wrap.units}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
global class SampleReport {
public String body{set;get;}
public list<integer> mylist{set;get;}
public List<ReportFields> consolewrapperlist{get;set;}
public SampleReport(){
}
public void SampleReportload(){
Httprequest req=new Httprequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string url='https://canvasjs.com/data/gallery/javascript/daily-sales-data.json';
req.setEndpoint(url);
req.setHeader('Content-type','application/json');
req.setMethod('GET');
res = http.send(req);
system.debug('=========res>>>'+res);
consolewrapperlist=new List<ReportFields>();
if(res.getstatusCode() == 200 && res.getbody() != null){
string body=res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('date','dates');
system.debug('==========>>>body....>'+body);
System.JSONParser jp=json.createParser(res.getbody());
system.debug('==.>>>jp'+jp);
while (jp.nextToken() != null) {
// find the stock part of the response
if (jp.getCurrentToken() == JSONToken.START_OBJECT) {
List<ReportFields> responseObject = (List<ReportFields>)JSON.deserialize(body,List<ReportFields>.class);
system.debug('responseObject ==> ' + responseObject );
List<Daily_sales_Data__c> dailyList = new List<Daily_sales_Data__c>();
for(ReportFields rf : responseObject )
{
Datetime dt = datetime.newinstance(long.valueOf(rf.dates));
Date datevalue = dt.date();
system.debug( 'dt ==> ' + datevalue );
rf.dates = String.ValueOf(datevalue);
Daily_sales_Data__c sd=new Daily_sales_Data__c();
sd.date__c=datevalue;
sd.units__c=Integer.valueOf(rf.units);
dailyList.add(sd);
}
consolewrapperlist.addall(responseObject);
if(dailyList.size() > 0)
insert dailyList;
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Data not find');
ApexPages.addMessage(myMsg);
}
}
public class ReportFields
{
public string dates {get;set;}
public string units{get;set;}
}
}
Thanks,
Maharajan.C
Try the below change class:
global class SampleReport {
public String body{set;get;}
public list<integer> mylist{set;get;}
public List<ReportFields> consolewrapperlist{get;set;}
public SampleReport(){
}
public void SampleReportload(){
Httprequest req=new Httprequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string url='https://canvasjs.com/data/gallery/javascript/daily-sales-data.json';
req.setEndpoint(url);
req.setHeader('Content-type','application/json');
req.setMethod('GET');
res = http.send(req);
system.debug('=========res>>>'+res);
consolewrapperlist=new List<ReportFields>();
if(res.getstatusCode() == 200 && res.getbody() != null && res.getbody() != '' ){
string body=res.getbody().replaceAll('\n','').replaceAll('\r','').replaceAll('date','dates');
system.debug('==========>>>body....>'+body);
List<ReportFields> responseObject = (List<ReportFields>)JSON.deserialize(body,List<ReportFields>.class);
system.debug('responseObject ==> ' + responseObject );
List<Daily_sales_Data__c> dailyList = new List<Daily_sales_Data__c>();
for(ReportFields rf : responseObject )
{
Datetime dt = datetime.newinstance(long.valueOf(rf.dates));
Date datevalue = dt.date();
system.debug( 'dt ==> ' + datevalue );
rf.dates = String.ValueOf(datevalue);
Daily_sales_Data__c sd=new Daily_sales_Data__c();
sd.date__c=datevalue;
sd.units__c=Integer.valueOf(rf.units);
dailyList.add(sd);
}
consolewrapperlist.addall(responseObject);
if(dailyList.size() > 0)
insert dailyList;
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Data not find');
ApexPages.addMessage(myMsg);
}
}
public class ReportFields
{
public string dates {get;set;}
public string units{get;set;}
}
}
Mark it as Best Answer !!! if it's Helps!!!
Thanks,
Maharajan.C
thanks it working,with using apex class need to display dashboard dynamically in einstein analytics can refresh time of interval dynamically.or everything need to run with apex code only.
Thanks & Regards,
Imran