You need to sign in to do that
Don't have an account?
pranavshah
Hi All,
I need to parse below code in JSON format to insert multiple records at a time... i have done for single record to be inserted...For inserting multiple records through web service , how it will be done
@RestResource(urlMapping='/showAccountDetails/*')
global with sharing class NewCustomerCreation
{
@HttpPost
global static string doPost(String name)
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
res.addHeader('Content-Type', 'application/json');
String jsonResponse = '';
String accountName = req.params.get('account_name');
Integer PInstallations = Integer.ValueOf(req.params.get('Potential_Installations__c'));
String Muncipaly = req.params.get('Municipaly__c');
String CustSegment = req.params.get('Customer_Segment_Lookup__c');
String CustHousingType = req.params.get('Housing_Type_Lookup__c');
String CustHousingOwnership = req.params.get('Housing_Ownership_Lookup__c');
//Inserting records into Account
Account acc= new Account();
acc.name=accountName;
acc.Potential_Installations__c= PInstallations;
acc.Municipaly__c='Muncipaly';
acc.Customer_Segment_Lookup__c ='CustSegment';
acc.Housing_Type_Lookup__c ='CustHousingType';
acc.Housing_Ownership_Lookup__c = 'CustHousingOwnership';
insert acc;
return acc.id;
}
below is the required format
{
"Account" :[{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"attributes" : "cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
}]
}
please help
Thanks & Regards
Pranav Shah
Apex Web Service- JSON Parsing for inserting multiple Records
Hi All,
I need to parse below code in JSON format to insert multiple records at a time... i have done for single record to be inserted...For inserting multiple records through web service , how it will be done
@RestResource(urlMapping='/showAccountDetails/*')
global with sharing class NewCustomerCreation
{
@HttpPost
global static string doPost(String name)
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
res.addHeader('Content-Type', 'application/json');
String jsonResponse = '';
String accountName = req.params.get('account_name');
Integer PInstallations = Integer.ValueOf(req.params.get('Potential_Installations__c'));
String Muncipaly = req.params.get('Municipaly__c');
String CustSegment = req.params.get('Customer_Segment_Lookup__c');
String CustHousingType = req.params.get('Housing_Type_Lookup__c');
String CustHousingOwnership = req.params.get('Housing_Ownership_Lookup__c');
//Inserting records into Account
Account acc= new Account();
acc.name=accountName;
acc.Potential_Installations__c= PInstallations;
acc.Municipaly__c='Muncipaly';
acc.Customer_Segment_Lookup__c ='CustSegment';
acc.Housing_Type_Lookup__c ='CustHousingType';
acc.Housing_Ownership_Lookup__c = 'CustHousingOwnership';
insert acc;
return acc.id;
}
below is the required format
{
"Account" :[{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"attributes" : "cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
},{
"cableunit_name":"",
"cableunit_number":"",
"potential_installation":"",
"municipality":"",
"postcode":"",
"customer_segment":"",
"Housing_type":"",
"building_type":"",
"housing_ownership":""
}
}]
}
please help
Thanks & Regards
Pranav Shah
All Answers
Is that correct ?