You need to sign in to do that
Don't have an account?
Manjunath reddy 6
Getting error message while using Rest api Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
Hi I am trying to do Integration between two different organizations in salesforce Using REST API and REST Web Service and Apex Web Service.For safety purpose I did'nt mention my credentials in the below code, actually in my org Iam using all the credentials perfectly, this code was working fine earlier, but now, Iam not abel to get response from the target org.I am getting the error message in the debug log "Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]", I am not able to figure out what is the issue? can some one help me on this.
My debug logs are as follows.
13:38:28.26 (28575173)|USER_DEBUG|[17]|DEBUG|===reqbody== grant_type=password&client_id=3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB& client_secret=3594199692394096988&username=manjunath@ceptes.com&password=Surya@12338VnYqobYUKwN718uV5oYB9Hy
13:38:28.26 (162542537)|USER_DEBUG|[19]|DEBUG|===res=== System.HttpResponse[Status=Not Found, StatusCode=404]
My debug logs are as follows.
13:38:28.26 (28575173)|USER_DEBUG|[17]|DEBUG|===reqbody== grant_type=password&client_id=3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB& client_secret=3594199692394096988&username=manjunath@ceptes.com&password=Surya@12338VnYqobYUKwN718uV5oYB9Hy
13:38:28.26 (162542537)|USER_DEBUG|[19]|DEBUG|===res=== System.HttpResponse[Status=Not Found, StatusCode=404]
public class SendAccountFromSource { private final String clientId = 'Clent Id from App'; private final String clientSecret = 'clientSecretfrom connected app'; private final String username = 'User name'; private final String password = 'passwordwithsecuritytoken'; public class deserializeResponse{ public String id; public String access_token; } public String ReturnAccessToken (SendAccountFromSource acount){ String reqbody = 'grant_type=password&client_id='+clientId+'& client_secret='+clientSecret+'& username='+username+'&password='+password; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setBody(reqbody); req.setMethod('POST'); req.setEndpoint('https://login.salesforce.com/services/oauth2/callback'); system.debug('===reqbody== '+reqbody); HttpResponse res = h.send(req); system.debug('===res=== '+res ); deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class); system.debug('===resp1.access_token== '+resp1.access_token); return resp1.access_token; } @future(callout=true) public static void createAccount(String accName, String accId){ SendAccountFromSource acount = new SendAccountFromSource(); system.debug('===acount == '+acount ); String accessToken = acount.ReturnAccessToken (acount); system.debug('===accessToken == '+accessToken ); if(accessToken != null){ String endPoint = 'https://ap2.salesforce.com/services/data/v32.0/sobjects/Account/'; String jsonstr = '{"Name" : "' + accName + '"}'; system.debug('===jsonstr == '+jsonstr ); Http h2 = new Http(); HttpRequest req1 = new HttpRequest(); req1.setHeader('Authorization','Bearer ' + accessToken); req1.setHeader('Content-Type','application/json'); req1.setHeader('accept','application/json'); req1.setBody(jsonstr); req1.setMethod('POST'); req1.setEndpoint(endPoint); HttpResponse res1 = h2.send(req1); system.debug('===res1 == '+res1 ); deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class); Account a = [SELECT Id FROM Account WHERE Id = :accId]; system.debug('===a==='+a); system.debug('===resp2== '+resp2 ); system.debug('===jsonstr == '+jsonstr ); update a; } } }
A common cause is that the server is responding with a HTML page that contains error information rather than the JSON. Typically the status code in the response res.getStatusCode() would also be some value other than the 2xx success codeshttps://en.wikipedia.org/wiki/List_of_HTTP_status_codes
For more information on similar, issue please check with below posts.
- http://stackoverflow.com/questions/33631523/unexpected-character-a-code-97-expected-a-valid-value-number-string-ar
- http://salesforce.stackexchange.com/questions/48755/getting-error-while-deserialize
Mark this post as solved if it's resolved.Best Regards,
Nagendra.P
Thanks for your response, I have resolved that issue on my own already, but I ned your help in the below code, can you help me on this.
Not able to access the variable from catch block, please help me on this.
I need help on the issue with my VF page, My VF page code and my controller code is as below.in the below code in y controller, I have created a boolean variable called dupRecord,which I made true in the catch block, I am trying to access dupRecord variable in the method in the closingTheTab method., as per debug logs, I am able to get dupRecord is true in the catch block, but Iam not able to get dupRecord variable as true in closingTheTab method, Iam trying to send dupRecord variable from apex;:param to duprecord2, but I am not gettting expected result, before that, I just made the dupRecord as true in catch block and tried accessin in the closingTheTab , but not able to get expected result, please help me on this.
001<apex:page standardController="HPE_Account_Team__c"extensions="GSDAccountteammembercontroller" sidebar="false" showHeader="false">
002<apex:pagemessages id="EMSG"/>
003<apex:includeScript value="/support/console/33.0/integration.js"/>
004<script type="text/javascript">
005
006 function RefreshPrimaryTab()
007 {
008 //var primaryTabId = 'navigatortab__scc-pt-1';
009 sforce.console.getFocusedPrimaryTabId(showTabId);
010 }
011
012 var showTabId = function showTabId(result)
013 {
014 var tabId = result.id;
015 sforce.console.refreshPrimaryTabById(tabId , true, refreshSuccess);
016 };
017
018 var refreshSuccess = function refreshSuccess(result)
019 {
020 //Report whether refreshing the primary tab was successful
021 if (result.success == true)
022 {
023 alert('Primary tab refreshed successfully');
024 }
025 else
026 {
027 alert('Primary did not refresh');
028 }
029 };
030
031
032function ClosetheTab() {
033 if(sforce.console.isInConsole()) {
034 sforce.console.getEnclosingTabId(closeSubtab);
035 //var primaryTabId = 'navigatortab__scc-pt-1';
036 sforce.console.getFocusedPrimaryTabId(showTabId);
037 }
038 else{
039 alert('hello it is out of console');
040 //window.location.href = location.protocol + '//' + window.location.hostname + '/' + '{!parentrecordid}';
041 //window.location.href = window.opener.location.href;
042 window.opener.refreshoutofconsole();
043 alert('hello it is out of console2');
044 window.top.close();
045
046 }
047 }
048 var closeSubtab = function closeSubtab(result) {
049
050 //Now that we have the tab ID, we can close it
051 var tabId = result.id;
052 sforce.console.closeTab(tabId);
053 };
054
055function CloseSavePage(TabToBeClosed){
056 alert('Now it is reached to CloseSavePage function');
057 alert(TabToBeClosed);
058 //TabToBeClosed=true;
059 //alert(TabToBeClosed);
060 if(TabToBeClosed==='true'){
061 ClosetheTab();
062 }
063 alert('Now it is reached to ClosetheTab function');
064}
065
066function CloseTaboncancel() {
067 if(sforce.console.isInConsole()) {
068 sforce.console.getEnclosingTabId(closeSubtab);
069 }
070 else{
071 window.top.close();
072 }
073}
074</script>
075 <apex:form >
076 <apex:actionFunction name="priorityChangedJavaScript" action="{!closingtheTab}"oncomplete="CloseSavePage('{!TabToBeClosed}');return false"/ >
077 <apex:pageblock >
078 <apex:pageBlockTable value="{!listofrecords}" var="Acc" id="pbt">
079 <apex:column headerValue="Name" style="width:250px">
080 <apex:inputField value="{!Acc.Name__c}" required="false" />
081 </apex:column>
082 <apex:column headerValue="Role">
083 <apex:inputField value="{!Acc.Role__c}" required="false"/>
084 </apex:column>
085 <apex:column headerValue="Role Scope">
086 <apex:inputField value="{!Acc.Role_Scope__c}" required="false"/>
087 </apex:column>
088 <apex:column headerValue="Role Scope Description">
089 <apex:inputField value="{!Acc.Role_Scope_Description__c}"style="width:600px"/>
090 </apex:column>
091 </apex:pageBlockTable>
092 <apex:pageBlockButtons >
093
094 <apex:commandButton action="{!SaveRecords}" value="Save" reRender="Pbt,EMSG"onclick="priorityChangedJavaScript()">
095 {!dupRecord};
096 {!dupRecord2};
097 <apex:param value="{!dupRecord}" assignTo="{!dupRecord2}"/>
098 {!dupRecord};
099 {!dupRecord2};
100 </apex:commandButton>
101
102 <apex:commandButton value="Cancel" onclick="CloseTaboncancel()"/>
103 </apex:pageBlockButtons>
104 </apex:pageblock>
105 </apex:form>
106</apex:page>
001public class GSDAccountteammembercontroller {
002 public list<HPE_Account_Team__c> listofrecords{get;set;}
003 public Boolean TabToBeClosed {get;set;}
004 public string parentrecordid{get;set;}
005 public HPE_Account_Team__c HPEAccountTeam{get;set;}
006 public string recieveID{get;set;}
007 public string currentAccountPageId{get;set;}
008 public boolean dupRecord{get;set;}
009 public boolean dupRecord2{get;set;}
010
011
012 //Constructor
013 public GSDAccountteammembercontroller(ApexPages.StandardController controller){
014 //tabTobeClosed = true;
015 dupRecord=false;
016 dupRecord2=false;
017 parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');//this line is for when the record is coming from the ASDP page
018 recieveID= ApexPages.currentPage().getParameters().get('sendasdpid');
019 system.debug('recieveID'+recieveID);
020 system.debug('parentrecordid'+parentrecordid);
021 HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
022 system.debug('HPEAccountTeam.id'+HPEAccountTeam.id);
023 if(HPEAccountTeam.account__c!=null){
024 recieveID=HPEAccountTeam.account__c;
025 }
026 system.debug('HPEAccountTeam'+HPEAccountTeam);
027 currentAccountPageId= ApexPages.currentPage().getParameters().get('id');
028 system.debug('currentAccountPageId'+currentAccountPageId);
029 if(parentrecordid == null || parentrecordid == ''){
030 system.debug('Enter parentrecordid '+parentrecordid );
031 parentrecordid = HPEAccountTeam.Account__c;
032 system.debug('Enter parentrecordid '+parentrecordid );
033 }
034
035 HPE_Account_Team__c accteam;
036 //tabToBeClosed = false;
037 listofrecords = new list<HPE_Account_Team__c>();
038 for(Integer i=accountConstants.Zero; i<accountConstants.Five ; i++){
039 accteam = new HPE_Account_Team__c();
040 listofrecords.add(accteam);
041 }
042 }
043
044
045 //Save method
046 public PageReference SaveRecords() {
047 list<HPE_Account_Team__c> AccountTeamtoBeInserted= new list<HPE_Account_Team__c>();
048 try{
049 //tabToBeClosed = true;
050 system.debug('Save parentrecordid '+parentrecordid );
051
052 for(HPE_Account_Team__c acctem :listofrecords){
053 acctem.Account__c = parentrecordid;
054 if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null){
055 AccountTeamtoBeInserted.add(acctem);
056 }
057 else if(acctem.Name__c != null || acctem.Role__c!=null || acctem.Role_Scope__c!=null ){
058 ApexPages.Message errorMessage= newApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
059 return null;
060 }
061 }
062 if(AccountTeamtoBeInserted.size() > 0)
063 insert AccountTeamtoBeInserted;
064 else{
065 ApexPages.Message errorMessage= newApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
066 //tabTobeClosed = false;
067 return null;
068 }
069 }
070 catch(Exception ex){
071 ApexPages.addMessages(ex);
072 //tabTobeClosed = false;
073 dupRecord= true;
074 system.debug('dupRecord' +dupRecord);
075 return null;
076 }
077
078 string BaseURL = URL.getSalesforceBaseUrl().toExternalForm();
079 system.debug('recieveID'+recieveID);
080 PageReference redirectTopage = new PageReference(BaseURL+'/'+recieveID);
081 redirectTopage.setRedirect(true);
082 return redirectTopage;
083 }
084
085 public void closingtheTab(){
086 system.debug('The value is before making true' +tabToBeClosed);
087 system.debug('dupRecord2' +dupRecord);
088 for(HPE_Account_Team__c acctem :listofrecords){
089 if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null){
090 system.debug('tabToBeClosed' +tabToBeClosed);
091 tabToBeClosed = true;
092 system.debug('tabToBeClosed' +tabToBeClosed);
093 system.debug('dupRecord' +dupRecord);
094 if(dupRecord2==true){
095 tabToBeClosed = false;
096 }
097 break;
098 }
099 else if(acctem.Name__c == null || acctem.Role__c == null || acctem.Role_Scope__c == null ){
100 system.debug('tabToBeClosed' +tabToBeClosed);
101 tabToBeClosed = false;
102 }
103 }
104 system.debug('The value is after making true' +tabToBeClosed);
105
106 }
107
108}