• S S Malik
  • NEWBIE
  • 30 Points
  • Member since 2015
  • Salesforce Developer
  • itutor.com

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 6
    Questions
  • 9
    Replies
Apex Class
public class Calloutcontroller {
    List<Tutor__c> TutorList ;
   
    // public Calloutcontroller() {
    //  }
    //  public Calloutcontroller(Tutor controller) {
    //  }
    //public Calloutcontroller(ApexPages.StandardController controller) {
    
    public List<consolewrap> ConsoleWrapperList{get;set;}
    public List<consolewrap> getperformcallout(){
     TutorList = new List<Tutor__c>();
    ConsoleWrapperList = new List<consolewrap>();
    HttpRequest req = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();
    req.setEndpoint('http://www.itutorindia.com/angularjs/api/smallWidget/tutorHourSalesForce');
    //req.setEndpoint('http://52.24.111.14/angularjs/api/smallWidget/tutorHourSalesForce');
    req.setMethod('GET');
    req.setHeader('Content-Type', 'application/json');
    req.setHeader('Accept','application/json');
    res = http.send(req);
    if(res.getstatusCode() == 200 && res.getbody() != null){
    system.debug('Response body result is+++: ' + res.getBody());
    ConsoleWrapperList=(List<consolewrap>)json.deserialize(res.getbody(),List<consolewrap>.class);
    
    /* To save Aoi data in custom object tutor*/
    
    Tutor__c tutorObj;
    system.debug('test1++++++++');
    for (integer i = 0; i<ConsoleWrapperList.size(); i++)
    {
    system.debug('test2++++++++');
    tutorObj = new Tutor__c();
    tutorObj.Class_ID__c = Integer.valueOf(ConsoleWrapperList[i].class_id);
    tutorObj.Tutor_ID__c = Integer.valueOf(ConsoleWrapperList[i].tutor_id);
    tutorObj.Class_Time__c =date.ValueOf(ConsoleWrapperList[i].class_time);
    //system.debug('time is++++ '+tutorObj.Class_Time__c);
    //system.debug('Time values entered');
    tutorObj.Name = ConsoleWrapperList[i].tutor_name;
    tutorObj.E_Mail__c = ConsoleWrapperList[i].tutor_email;
    tutorObj.Tutor_Phone__c = ConsoleWrapperList[i].tutor_phone;
    TutorList.add(tutorObj);
   // system.debug('test3++++++++');
    }
    //system.debug('TutorList++++++++'+TutorList);
    }
    //system.debug('Time values entered222');
    upsert TutorList;
    system.debug('Time values entered+++++++');
    return ConsoleWrapperList;
}
    }
-----------------------------------------------------------
Wrapper class
public class consolewrap {

public String class_id{get;set;}

public String class_time{get;set;}

public String tutor_id{get;set;}

public String tutor_name{get;set;}

public String tutor_email{get;set;} 

public String tutor_phone{get;set;}
}
-------------------------------------------------------------------------------
VF PAGE
<apex:page Controller="Calloutcontroller" title="JSON Tutors table">

<apex:form >

<apex:pageBlock >

<apex:pageBlockTable value="{!performcallout}" var="wrap">

<apex:column headerValue="Class Id" value="{!wrap.class_id}"/>

<apex:column headerValue="Class Time" value="{!wrap.class_time}"/>

<apex:column headerValue="Tutor Id" value="{!wrap.tutor_id}"/>

<apex:column headerValue="Tutor Name" value="{!wrap.tutor_name}"/>

<apex:column headerValue="Tutor Email" value="{!wrap.tutor_email}"/>

<apex:column headerValue="Tutor Phone" value="{!wrap.tutor_phone}"/>

</apex:pageBlockTable>

</apex:pageBlock>

</apex:form>
</apex:page>
Hi Developers
I am facing this error
Please help me to solve this problem and my code are
Class# consolewrap 
public class consolewrap {

public String class_id{get;set;}

public String class_time{get;set;}

public String tutor_id{get;set;}

public String tutor_name{get;set;}

public String tutor_email{get;set;} 

public String tutor_phone{get;set;}

}

Class # Calloutcontroller 
public class Calloutcontroller {

public List<consolewrap> ConsoleWrapperList{get;set;}

public List<consolewrap> getperformcallout(){

ConsoleWrapperList = new List<consolewrap>();

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();

req.setEndpoint('http://www.itutorindia.com/angularjs/api/smallWidget/tutorHourSalesForce');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<consolewrap>)json.deserialize(res.getbody(),List<consolewrap>.class);
}
return consolewrapperlist;
}
}

VF PAGE #
<apex:page controller="Calloutcontroller" title="JSON table" >
<apex:form > <apex:pageBlock >
<apex:pageBlockTable value="{!performcallout}" var="wrap">
<apex:column headerValue="class id" value="{!wrap.class_id}"/>
<apex:column headerValue="class time" value="{!wrap.class_time}"/>
<apex:column headerValue="tutor id" value="{!wrap.tutor_id}"/>
<apex:column headerValue="tutor name" value="{!wrap.tutor_name}"/>
<apex:column headerValue="tutor email" value="{!wrap.tutor_email}"/>
<apex:column headerValue="tutor phone" value="{!wrap.tutor_phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

I had made the remote site also
Hi all Developer
I am new to salesforce integration and need to implement the integration between PHP website database table's value into the Salesforce object
Please guide me how I can implement this 
and what requirment to be given to PHP Dev team for the webservice/and JSON to access PHP website data into Salesforce Object

Thanks in Advance
Sukhbir
email erssmalik@gmail.com
The code is as
public class testcallouts{
    public static httpResponse MakeGetCallout(){
    http http=new Http();
    HttpRequest request=new HttpRequest();
    request.setEndpoint('https://www.itutorlms.com/test.php');
    request.setMethod('GET');
    httpResponse response =http.send(request);
    if(response.getStatusCode() == 200) {
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    List<String> key = (List<String>) results.get('names');
    System.debug('Received the following names:');
     for(String key1:results.keySet())

System.debug(results.get(key1));
}}}
    public static httpResponse MakePostCallout(){
    Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"sukhbir"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
    system.debug('Test Start from Here');
    System.debug(response.getBody());
    //System.debug('The status code returned was not expected: ' +
      //  response.getStatusCode() + ' ' + response.getStatus());
}
        else {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
    //System.debug(response.getBody());
    //System.debug(response.getBody());
    system.debug('TEST ENDS HERE');
}
//system.debug('success Ending');
        return response;
}   
}

Thanks in Advance
Hello friends
I am doing the POST Request and trying to add a value to current availble JSON
and Getting the error
" |DEBUG|The status code returned was not expected: 200 OK"
and my code is 

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"sukhbir"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}

and please suggest me any particular website for learning callouts and API step by step

Thanks in advance
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'Name' key as a list
    List<String> names = (List<String>) results.get('names');
    System.debug('Received the following names:');
    for(Object name :'names')
        {
        System.debug(name);
        }
}
Hi Developers
I am facing this error
Please help me to solve this problem and my code are
Class# consolewrap 
public class consolewrap {

public String class_id{get;set;}

public String class_time{get;set;}

public String tutor_id{get;set;}

public String tutor_name{get;set;}

public String tutor_email{get;set;} 

public String tutor_phone{get;set;}

}

Class # Calloutcontroller 
public class Calloutcontroller {

public List<consolewrap> ConsoleWrapperList{get;set;}

public List<consolewrap> getperformcallout(){

ConsoleWrapperList = new List<consolewrap>();

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();

req.setEndpoint('http://www.itutorindia.com/angularjs/api/smallWidget/tutorHourSalesForce');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<consolewrap>)json.deserialize(res.getbody(),List<consolewrap>.class);
}
return consolewrapperlist;
}
}

VF PAGE #
<apex:page controller="Calloutcontroller" title="JSON table" >
<apex:form > <apex:pageBlock >
<apex:pageBlockTable value="{!performcallout}" var="wrap">
<apex:column headerValue="class id" value="{!wrap.class_id}"/>
<apex:column headerValue="class time" value="{!wrap.class_time}"/>
<apex:column headerValue="tutor id" value="{!wrap.tutor_id}"/>
<apex:column headerValue="tutor name" value="{!wrap.tutor_name}"/>
<apex:column headerValue="tutor email" value="{!wrap.tutor_email}"/>
<apex:column headerValue="tutor phone" value="{!wrap.tutor_phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

I had made the remote site also
Hi all Developer
I am new to salesforce integration and need to implement the integration between PHP website database table's value into the Salesforce object
Please guide me how I can implement this 
and what requirment to be given to PHP Dev team for the webservice/and JSON to access PHP website data into Salesforce Object

Thanks in Advance
Sukhbir
email erssmalik@gmail.com
The code is as
public class testcallouts{
    public static httpResponse MakeGetCallout(){
    http http=new Http();
    HttpRequest request=new HttpRequest();
    request.setEndpoint('https://www.itutorlms.com/test.php');
    request.setMethod('GET');
    httpResponse response =http.send(request);
    if(response.getStatusCode() == 200) {
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    List<String> key = (List<String>) results.get('names');
    System.debug('Received the following names:');
     for(String key1:results.keySet())

System.debug(results.get(key1));
}}}
    public static httpResponse MakePostCallout(){
    Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"sukhbir"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
    system.debug('Test Start from Here');
    System.debug(response.getBody());
    //System.debug('The status code returned was not expected: ' +
      //  response.getStatusCode() + ' ' + response.getStatus());
}
        else {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
    //System.debug(response.getBody());
    //System.debug(response.getBody());
    system.debug('TEST ENDS HERE');
}
//system.debug('success Ending');
        return response;
}   
}

Thanks in Advance
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'Name' key as a list
    List<String> names = (List<String>) results.get('names');
    System.debug('Received the following names:');
    for(Object name :'names')
        {
        System.debug(name);
        }
}
Hi all,

I have used the endpoint url as '' http://api.walmartlabs.com/v1/feeds/specialbuy?apikey=mmbwyhxhzapcqn5pu8mnaqmw&categoryId=3944 ". Up to yester day it worked properly. But now, I when I am running my application I am getting the error "FATAL_ERROR|System.JSONException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [3,2]".

I checked in debug logs. There I found status as "HttpResponse[Status=Server Error, StatusCode=500]".How can I resolve this ? Please someone help me.
 
I am working with the new JSON Parsing functionality,
I have API URL that contain json string.I have created one VF page that displays JSON string data in pageblock table in record format from API URL.
Now i want to insert that json string into custom object records. How can I insert new records fron json string to my custom object.
Hi,

I am trying to import the custom object through Data Import Wizard but getting the error :The required field Currency is not mapped.
I had import the successfully using Data loader and Workbench .But facing problem while using Data Import Wizard.

User-added image

 

when i try to parse the string

 

 

with this code

             counter=0;
                while (parser.nextToken() != null && counter<10)
                {
                counter++;
                    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'total_records'))
                     {
                     
                            // Get the value.
                                parser.nextToken();
                            // Compute the grand total price for all invoices.
                            Temp=parser.getText();
                            file_count=integer.valueof(Temp);
                            if(file_count==0)
                            {
                             file_exists=0;
                            
                             }
                           // csv_ids.add( Temp);
                      }
                }
                counter=0;
                 
my json string is

{"success":true,"total_records":1,"data":[{"file_name":"aaavalid.csv"}]}

 

 

 

 

Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,4]
An unexpected error has occurred. Your solution provider has been notified. (system)

How do i resolve this problem

Thanks in advance

punnoose

Hi,

I am trying to import the custom object through Data Import Wizard but getting the error :The required field Currency is not mapped.
I had import the successfully using Data loader and Workbench .But facing problem while using Data Import Wizard.

User-added image