4

I run in an issue with calling APEX out of JavaScript, when i call my APEX class, the class is executed with API-version 34.0, but in the metadata of this class is the API-version set to 27.0. I need 27.0 because there is a change how fields with null values are represented in the JSONized Query, before 28.0 the fields where included afterwards not anymore. I've found a solution, but not a perfect one, i just put the logic in an @future method and everything is running fine. But this is not a solution for every case i try to solve. Here some code snippets to try out:

 global class fetchJSONDataMaster{
  webservice static void JSONFetchData(){
    fetchJSONDataFuture.CalledMethod();
  }
  webservice static void JSONFetchDataNoFuture(){
    fetchJSONData.CalledMethod();
  }
}
public class fetchJSONDataFuture{
@future
  public static void CalledMethod(){
    String query_full = ('SELECT AccountId, AssistantName, AssistantPhone, Birthdate, Fax, Phone, Description, Id, CreatedById, CreatedDate, IsDeleted, Department, EmailBouncedDate, EmailBouncedReason, FirstName, Name, HomePhone, LastActivityDate, LastModifiedById, LastModifiedDate, LastName, LastCURequestDate, LastCUUpdateDate, LeadSource, MailingCity, MailingCountry, MailingState, MailingStreet, MailingPostalCode, MasterRecordId, MobilePhone, OtherCity, OtherCountry, OtherPhone, OtherState, OtherStreet, OtherPostalCode, OwnerId, ReportsToId, Salutation,  SystemModstamp, Title FROM Contact LIMIT 10');
    SObject[] s = database.query(query_full);
    System.debug(JSON.serialize(s));
  }
  }
public class fetchJSONData{
  public static void CalledMethod(){
    String query_full = ('SELECT AccountId, AssistantName, AssistantPhone, Birthdate, Fax, Phone, Description, Id, CreatedById, CreatedDate, IsDeleted, Department, EmailBouncedDate, EmailBouncedReason, FirstName, Name, HomePhone, LastActivityDate, LastModifiedById, LastModifiedDate, LastName, LastCURequestDate, LastCUUpdateDate, LeadSource, MailingCity, MailingCountry, MailingState, MailingStreet, MailingPostalCode, MasterRecordId, MobilePhone, OtherCity, OtherCountry, OtherPhone, OtherState, OtherStreet, OtherPostalCode, OwnerId, ReportsToId, Salutation,  SystemModstamp, Title FROM Contact LIMIT 10');
    SObject[] s = database.query(query_full);
    System.debug(JSON.serialize(s));
  }
  }

And the calling JavaScript:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")}
sforce.apex.execute("fetchJSONDataMaster","JSONFetchData",{});
sforce.apex.execute("fetchJSONDataMaster","JSONFetchDataNoFuture",{});

I have no Idea if its a bug or a feature! Maybe someone of you! I hope someone can help me!

Small Edit: You need to set the API Version fetchJSONData and fetchJSONDataFuture to 27.0. You can do this via something like Sublime with Mavensmateor any other IDE which supports changes on the metadata.

Edit 2: The outcome of both calls is different! Without @future the null values arent included in the JSON.

Edit 3: The difference between the two calls is that the @future method runs in its own execution context while the method without @future runs in the execution context of the class called out of JS.

I've already tried to set the API-version of the class called out of JS to 27.0. It doesn't changes nothing

5
  • You are seeing what I would expect: the version number of the Apex class is respected. I don't ever remember any suggestion that the version number of the JavaScript client code will be propagated through into the Apex. (The SOAP API version in connection.js does match the version number of the JavaScript e.g. "/services/Soap/u/27.0" in your case but that is a different API.)
    – Keith C
    Commented Sep 7, 2015 at 10:05
  • @KeithC I think i need to provide some more information. The Outcome of both calls is different! I dont think this is the expected outcome if i am right.
    – Nils Rosen
    Commented Sep 7, 2015 at 10:19
  • 1
    OK probably I'm not following fully. Perhaps someone else can figure it out.
    – Keith C
    Commented Sep 7, 2015 at 10:28
  • Thanks for the help to make the question understandable!
    – Nils Rosen
    Commented Sep 7, 2015 at 10:32
  • Did you solve this problem? I have a similar issue at salesforce.stackexchange.com/questions/245843/… Commented Jan 8, 2019 at 17:02

0

You must log in to answer this question.