• Jayesh Sonawane
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi everyone,

I am generating the whole html table in the controller on basis of the paramerter from & to date & displaying it from outputtext inside table tag.

the Constructor is working properly, it is generating the table_data on basis of default from & to date & rendering in the outputtext inside a table like this
User-added image
but when i am applying the date filter & regenerating the table_data in updateResp() method  on click of a command link 
it is generating the whole table_data but showing it outside the table
User-added image
here the vfp code
<apex:page sidebar="false" controller="misGeneratorController" showHeader="false" docType="html-5.0">
        <head>
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css"/>
        </head>
        <body>
          <div class="container">
              <div class="row">
                  <apex:form >
                  <div class="input-field col m5 s12">
                    <select multiple="multiple">
                      <option value=""  disabled="disabled">All City</option>
                        <apex:repeat value="{!cities}" var="city">
                            <option value="{!city}" selected="true"> {!city}</option>
                        </apex:repeat>
                   </select>
                  </div>                
                  <div class="input-field col m3 s12">
                      <apex:input value="{!fromDate}"  type="date" styleClass="datepicker" /> 
                  </div>    
                  <div class="input-field col m3 s12">
                      <apex:input value="{!toDate}" type="date" styleClass="datepicker"/> 
                  </div>
                  <div class="input-field col m1 s12">
                          <apex:commandLink value="Apply" styleClass="chip"  action="{!updateResp}" reRender="table_data"/>
                      
                  </div>
				</apex:form>
              </div>
              
              <table class="bordered">
                  <apex:outputText id="table_data" value="{!table_data}"  escape="false" ></apex:outputText>
              </table>   
              
          </div>
        </body>
</apex:page>
after the click on the command link  the output is showing outside the table in a span, the table data is not even changing
here's the controller
public class misGeneratorController {
    public list<String> cities {get;set;}
    public date fromDate{get;set;}
    public date toDate{get;set;}
    public String thead {get;set;}
    public String tbody {get;set;}
    public String table_data {get;set;}
	 public misGeneratorController()
     {
          cities = new String[]{'Mumbai','Pune','Delhi','Banglore','Hyderabad','Ghaziabad','Faridabad','Gurgaon'};
          fromDate = date.today();
          toDate = fromDate.addDays(4);
          thead = makeHeader(fromDate, toDate);
          tbody = makeBody(fromDate, toDate);
          table_data = thead + tbody;
     }
    public PageReference updateResp()
    {
          table_data = '';
          thead = makeHeader(fromDate, toDate);
          tbody = makeBody(fromDate, toDate);
          table_data = thead + tbody;
          return null;
    }
    public String makeHeader(date from_date , date to_date)
    {
         String thead_str = '<thead>';
         thead_str += '<tr><th>Cities</th>';
         integer day_diff = from_date.daysBetween(to_date);
         for (integer i=0;i<=day_diff ;i++)
         {
             Date c_fd = from_date.addDays(i);
             c_fd = Date.newInstance(c_fd.year(),c_fd.month(),c_fd.day());
             thead_str += '<th >'+ c_fd.format()+'</th>';
         }
         thead_str += '</tr>';
         thead_str += '</thead>';
        return thead_str;
    }
    public String makeBody (date from_date , date to_date)
    {
        String tbody_str ='<tbody>';
        for (String city:cities)
        {
	         tbody_str += '<tr>';
             tbody_str += '<td>' + city + '</td>';
             integer day_diff = from_date.daysBetween(to_date);
             for (integer i=0;i<=day_diff;i++)
             {
                tbody_str += '<td >'+ from_date.addDays(i).day()+'</td>';
             }
             tbody_str += '</tr>';
         }
         
         tbody_str += '</tbody>';
		 return tbody_str;
    }
}
Please rectify me where i am going wrong.

Thanks
 
hi everyone,

I am calling an API with Authtoken in header :
        String resp = 'response : ';
        HttpRequest req = new HttpRequest();
        JSONGenerator gen = JSON.createGenerator(false);
        JSONGenerator gen = JSON.createGenerator(false);
  		String  url = 'http://api.xxxxx.com/xx/xxx/xxx';
        
        	req.setEndpoint(url);
			String reqJSON;
                        gen.writeStartObject();
                        gen.writeStringField ('transaction_id', txnID);
                        gen.writeEndObject();
                        
                        // Get the JSON string.
                        reqJSON = gen.getAsString();        
	        req.setBody(reqJSON);
			req.setEndpoint (url);
	        req.setHeader('Authorization', 'Token xxxxxxxxxxxxxxxxxxxxxxxx');
        
                        req.setMethod ('GET');
                        req.setHeader('Content-Type', 'application/json');
                        req.setHeader('Accept', 'application/json');
                        req.setBody(reqJSON);
                        req.setTimeout(60000);
                      // Get response

        httpResponse res = new http().send(req);
		resp = resp + ' : ' + res.getBody() + ' - '  + res.toString();
	    ApexPages.addMessage(new ApexPages.Message( ApexPages.Severity.info,resp));
but the output i am able to see is this 
response : : - System.HttpResponse[Status=Moved Permanently, StatusCode=301]
​what may be the issue here ,
  • I have checked the API , its working fine on Postman and other platform.
  • I have added the api url on Remote Sites.
Is there any thing else i am missing here ?
 
The challenge is to Create an Apex class naming StringArrayTest having function generateStringArray that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.

So I  have created following StringArrayTest Class with generateStringArray function.

public class StringArrayTest {
    public static String[] generateStringArray(Integer n)
    {
        String[] testList = new List<String>();
            for (Integer i=0;i<n;i++)
            {
                testList.add('Test'+i);
            }
            return testList;
    }
}

But when i click on Ckeck Challenge. it is showing following error : 
Challenge Not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.

Whats Wrong in here ?
The challenge is to Create an Apex class naming StringArrayTest having function generateStringArray that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.

So I  have created following StringArrayTest Class with generateStringArray function.

public class StringArrayTest {
    public static String[] generateStringArray(Integer n)
    {
        String[] testList = new List<String>();
            for (Integer i=0;i<n;i++)
            {
                testList.add('Test'+i);
            }
            return testList;
    }
}

But when i click on Ckeck Challenge. it is showing following error : 
Challenge Not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.

Whats Wrong in here ?
hi everyone,

I am calling an API with Authtoken in header :
        String resp = 'response : ';
        HttpRequest req = new HttpRequest();
        JSONGenerator gen = JSON.createGenerator(false);
        JSONGenerator gen = JSON.createGenerator(false);
  		String  url = 'http://api.xxxxx.com/xx/xxx/xxx';
        
        	req.setEndpoint(url);
			String reqJSON;
                        gen.writeStartObject();
                        gen.writeStringField ('transaction_id', txnID);
                        gen.writeEndObject();
                        
                        // Get the JSON string.
                        reqJSON = gen.getAsString();        
	        req.setBody(reqJSON);
			req.setEndpoint (url);
	        req.setHeader('Authorization', 'Token xxxxxxxxxxxxxxxxxxxxxxxx');
        
                        req.setMethod ('GET');
                        req.setHeader('Content-Type', 'application/json');
                        req.setHeader('Accept', 'application/json');
                        req.setBody(reqJSON);
                        req.setTimeout(60000);
                      // Get response

        httpResponse res = new http().send(req);
		resp = resp + ' : ' + res.getBody() + ' - '  + res.toString();
	    ApexPages.addMessage(new ApexPages.Message( ApexPages.Severity.info,resp));
but the output i am able to see is this 
response : : - System.HttpResponse[Status=Moved Permanently, StatusCode=301]
​what may be the issue here ,
  • I have checked the API , its working fine on Postman and other platform.
  • I have added the api url on Remote Sites.
Is there any thing else i am missing here ?
 
The challenge is to Create an Apex class naming StringArrayTest having function generateStringArray that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.

So I  have created following StringArrayTest Class with generateStringArray function.

public class StringArrayTest {
    public static String[] generateStringArray(Integer n)
    {
        String[] testList = new List<String>();
            for (Integer i=0;i<n;i++)
            {
                testList.add('Test'+i);
            }
            return testList;
    }
}

But when i click on Ckeck Challenge. it is showing following error : 
Challenge Not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.

Whats Wrong in here ?