function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IanHulmeIanHulme 

Execute Apex in Native iOS App

Hi All,

 

In the Hybrid app you can use Javascript to run apex to send pdfs, for example:

            sforce.apex.execute("inspections","sendPdf",{email:$email, inspId:$inspId, inspAssId:$inspAssId});

 

Is it possible to run this sort of code from a native app, or would I have to build and email the pdf natively on the device.

 

Many Thanks,

Ian

SamuelDeRyckeSamuelDeRycke

I have no experience with mobile development, but as no one is giving you an answer, I might as well share my opinion.

 

Would it not make more sense to have a REST webservice on the force platform do that functionality ? So that your native application just calls that service with required arguments ?

You likely have the code and functionality somewhere in apex already anyhow.

Gaurav KheterpalGaurav Kheterpal

You can use the REST API approach. You mentioned that In your apex page you are able to send email with attachment using your apex code. I would recomend exposing a REST method on the server side, for example

@RestResource(urlMapping='/GetService/*')
global with sharing class getservice1
{
@HttpGet
global static String postRestMethod(RestRequest req, RestResponse res)
{
return 'Hi, You have invoked getservice1 created using Apex Rest and exposed using REST API';
}
}

 

On the client side, invoke this method (JavaScript/ Apex). For example

 

 

public class getservice2
{
public String myresponse{get;set;}
public Pagereference getResult()
{
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = instanceUrl + '/services/apexrest/GetService';
req.setEndpoint(url);
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
HTTPResponse resp = http.send(req);
myresponse=resp.getBody();

return null; }
}  

 

This is an example of how to do it. You'll obviously need to implement the client side stuff in Objective C but I'm hoping you get the idea.

 

 

Regards,
Gaurav

IanHulmeIanHulme

Thanks for your replys, I'm still trying to figure this one out.

 

How you said is bang on, but the documentation for converting javascript to objective-c is limited at best.

 

I though I could do it with triggers and setup an object to hold the email plus relavent IDs, but when it comes to getcontent() to attach to email it fails.

 

If there is any way round this I'd be happy if some could let me know as it is done then.

 

but failing that, all i would need to know is how to call an apex class from objective-c.

 

again, thanks for your help.

Ian

SamuelDeRyckeSamuelDeRycke

Well, if you expose apex classes as RestResource services  like gauravkheterpal posted, you could do a http rest request from objective-c. I have no knowledge about objective c , but i'd assume that is possible and well documentated if you look ingo objective c documentation not specific for force.com integration ?