How insert row in data table from custom business logic ?
Hi!
All methods from Android SDK available from custom server code.
Android SDK doc: http://backendless.com/documentation/data/android/data_saving_data_objects.htm
Here is example for you:
@BackendlessEvent( "customEvent" )
public class CustomEventEventHandler extends com.backendless.servercode.extension.CustomEventHandler
{
@Override
public Map handleEvent( RunnerContext context, Map eventArgs )
{
String appId = context.getAppId().toString();
Contact contact = new Contact();
contact.setName( appId );
contact.setAge( 147 );
contact.setPhone( "777-777-777" );
contact.setTitle( "Favorites" );
Contact savedContact = Backendless.Persistence.save( contact );
return Collections.emptyMap();
}
}
Or you can use added project:
- Open attached project in IDEA
- Select Bootstrap.java and set your app id and secret key (use secret key for code runner)
- Build project
- Run CodeRunner.sh
- For example, run REST request to invoke handler:
curl
-H application-id:<your app id>
-H secret-key:<rest secret key>
-H Content-Type:application/json
-H application-type:REST
-X POST
-v [url=https://api.backendless.com/v1/servercode/events/customEvent]https://api.backendless.com/v1/servercode/events/customEvent[/url] -d '{}'
- Check added Contact table on data page
Link to project: https://drive.google.com/file/d/0B0Q96QP8p-3UQmFRdDVKbWtuNkU/view?usp=sharing
Regards,
Kate.