• Pete1234
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Ahhh what fun writing unit tests for the REST API, there seems to be quite a few posts about this and I'm afraid I'm going to add another.

 

I have an Apex REST class that uses a custom class called SAPAccount to hold the details of a JSON message I'm receiving.

 

global static SAPAccount[] doPost( SAPAccount[] sapsoldtos ){
... logic here...
}

 

When I try and call this method in my test class I get the error message "Illegal assignment from LIST<SAPAccountREST.SAPAccount> to SAPAccountREST.SAPAccount".

 

In the test class I'm creating a list of SAPAccounts and then adding to that list.

 

List<SAPAccountREST.SAPAccount> sapAcctList = new List<SAPAccountREST.SAPAccount>();
String jsonMsg = '';

SAPAccountREST.SAPAccount jsonSapAcct = new SAPAccountREST.SAPAccount();
jsonSapAcct.E1KNA1M_KUNNR = '0000000001';
jsonSapAcct.E1KNA1M_NAME = 'Customer Name';
jsonSapAcct.E1KNA1M_STRAS = 'Street';
jsonSapAcct.E1KNA1M_ORT01 = 'Town';
jsonSapAcct.E1KNA1M_PSTLZ = 'Postal Code';
jsonSapAcct.E1KNA1M_LAND1 = 'Country';
jsonSapAcct.E1KNA1M_STCEG = 'Vat';
		
sapAcctList.add( jsonSapAcct );
jsonMsg = JSON.serialize( jsonSapAcct );

 

I then try and call the Apex method using the following code which is when of course the error occurs:

 

SAPAccountREST.SAPAccount results = SAPAccountREST.doPost( sapAcctList );

 

Would greatly appreciate any help that anyone could provide.

Hi all,

 

Sorry for the newbie questions, but I've been hunting around for some information on how to use JSON in Salesforce and found some good resources however I've still got some questions about how Salesforce can receive a JSON feed from another system and process the results accordingly.

 

The scenario is Salesforce will be receiving a regular feed of master data (finance accounts) from an ERP system. Specifically the quetions I have are:

 

  1. I've found examples that show how to serialise and deserialise JSON messages, however how is the JSON Apex Class exposed so the sending system can deliver it's message?
  2. How is the request authenticated?
  3. How do you map the JSON message onto a Custom Object? Is it simply a case of looping through the message once it's deserialised and insert / upserting into the object?

Any help or pointers gratefully received.

Ahhh what fun writing unit tests for the REST API, there seems to be quite a few posts about this and I'm afraid I'm going to add another.

 

I have an Apex REST class that uses a custom class called SAPAccount to hold the details of a JSON message I'm receiving.

 

global static SAPAccount[] doPost( SAPAccount[] sapsoldtos ){
... logic here...
}

 

When I try and call this method in my test class I get the error message "Illegal assignment from LIST<SAPAccountREST.SAPAccount> to SAPAccountREST.SAPAccount".

 

In the test class I'm creating a list of SAPAccounts and then adding to that list.

 

List<SAPAccountREST.SAPAccount> sapAcctList = new List<SAPAccountREST.SAPAccount>();
String jsonMsg = '';

SAPAccountREST.SAPAccount jsonSapAcct = new SAPAccountREST.SAPAccount();
jsonSapAcct.E1KNA1M_KUNNR = '0000000001';
jsonSapAcct.E1KNA1M_NAME = 'Customer Name';
jsonSapAcct.E1KNA1M_STRAS = 'Street';
jsonSapAcct.E1KNA1M_ORT01 = 'Town';
jsonSapAcct.E1KNA1M_PSTLZ = 'Postal Code';
jsonSapAcct.E1KNA1M_LAND1 = 'Country';
jsonSapAcct.E1KNA1M_STCEG = 'Vat';
		
sapAcctList.add( jsonSapAcct );
jsonMsg = JSON.serialize( jsonSapAcct );

 

I then try and call the Apex method using the following code which is when of course the error occurs:

 

SAPAccountREST.SAPAccount results = SAPAccountREST.doPost( sapAcctList );

 

Would greatly appreciate any help that anyone could provide.

Hi all,

 

Sorry for the newbie questions, but I've been hunting around for some information on how to use JSON in Salesforce and found some good resources however I've still got some questions about how Salesforce can receive a JSON feed from another system and process the results accordingly.

 

The scenario is Salesforce will be receiving a regular feed of master data (finance accounts) from an ERP system. Specifically the quetions I have are:

 

  1. I've found examples that show how to serialise and deserialise JSON messages, however how is the JSON Apex Class exposed so the sending system can deliver it's message?
  2. How is the request authenticated?
  3. How do you map the JSON message onto a Custom Object? Is it simply a case of looping through the message once it's deserialised and insert / upserting into the object?

Any help or pointers gratefully received.