+ Start a Discussion
pooja biswaspooja biswas 

untyped json data

Hi
I have a strange requirement. 
I am getting data from an external websersive after making HttpCallout and I want to load the data into LeadObject, say Name , phone etc.
Json data contains many records.
The problem is the fields in standard Lead object and json data do not match
Json field name : fullname , myphone while in Lead object it is firstname , lastname etc

case 1: how to map these fields

case 2. If json data is like this: fullname=salesforce#cloud, so in lead object I want to have  firstname=salesforce and lastname=cloud

How to handle this?
any inputs pls elaborate.

thanks
pooja

 
Leo10Leo10
Hi,
Did you write the wrapper class to receive data from external web service? If not, you can write a wrapper class and map the fields.
Thank you.    
pooja biswaspooja biswas
Hi nabeel
I cam write wrapper class if field names match. I hope I am right.
In this case field names are different.so how it will map?

pooja
 
Leo10Leo10
Hi
Try this
you have to change with your custom names.
wrapper.firstname=objectInstance.fullname.substring(0,fullname.indexOf(' '));
wrapper.lasttname=objectInstance.fullname.substring(fullname.indexOf(' ')+1);

 
pooja biswaspooja biswas
Hi Nabeel
I got some idea. thanks
One more point if I may ask.

I have custom webservice which comes from an external api or assume that its defined in apex controller.
In an visual force page when I click a button, How to call this webservice using javascript remoting, assuming webservice returns a parameter & also takes a parameter?

thanks
pooja
 
Leo10Leo10
Hi,
You can use Ajax Toolkit provided by Salesforce for your purpose. The AJAX Toolkit is a JavaScript wrapper around the API and can be used instead of VF and Apex.
1. Create a custom button which executes JavaScript on its click.
2. Use Ajax Toolkit to perform the operations. You can perform SOQL and DML operation in Ajax Toolkit.

You can also refer these links
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm
https://andyinthecloud.com/2013/07/16/how-to-call-apex-code-from-a-custom-button/



Please mark this as best answer if this helps.

Thanks
Nabeel