• Pasquale Iodice
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi everyone,
after completed this trailhead: 
https://trailhead.salesforce.com/projects/mobilesdk_setup_dev_tools  for "Set Up Your Mobile SDK Developer Tools", I tried to develope my first hybrid app following this guide:
https://trailhead.salesforce.com/trails/mobile_sdk_intro/modules/mobile_sdk_hybrid/units/mobilesdk_hybrid_getting_started
but i'm having some trouble.

This is my command: 

C:\Users\iodicepa\Desktop\Mobile_SDK_projects>forcedroid create
Enter your application type (native, native_kotlin, react_native, hybrid_local,
hybrid_remote): hybrid_remote
Enter your application name: myapp
Enter the package name for your app (com.mycompany.myapp): com.paco.myapp
Enter your organization name (Acme, Inc.): paco
Enter the start page for your app: /apex/myRemote
Enter output directory for your app (leave empty for the current directory):


and this the error:

********************************************************************************

*
*   Creating android hybrid_remote application using Salesforce Mobile SDK
*     with app name:        myapp
*          package name:    com.paco.myapp
*          organization:    paco
*
*     in:                   myapp
*
*     from template repo:   https://github.com/forcedotcom/SalesforceMobileSDK-T
emplates#v5.3.0
*          template path:   HybridRemoteTemplate
*          start page:      /apex/myRemote
*          plugin repo:     https://github.com/forcedotcom/SalesforceMobileSDK-C
ordovaPlugin#v5.3.0
*
********************************************************************************


Creating a new cordova project.
C:\Users\iodicepa\Desktop\Mobile_SDK_projects\myapp C:\Users\iodicepa\Desktop\Mo
bile_SDK_projects
C:\Users\iodicepa\Desktop\Mobile_SDK_projects\myapp
`-- shelljs@0.7.0
  +-- glob@7.1.2
  | +-- fs.realpath@1.0.0
  | +-- inflight@1.0.6
  | | `-- wrappy@1.0.2
  | +-- inherits@2.0.3
  | +-- minimatch@3.0.4
  | | `-- brace-expansion@1.1.8
  | |   +-- balanced-match@1.0.0
  | |   `-- concat-map@0.0.1
  | +-- once@1.4.0
  | `-- path-is-absolute@1.0.1
  +-- interpret@1.0.4
  `-- rechoir@0.6.2
    `-- resolve@1.4.0
      `-- path-parse@1.0.5

C:\Users\iodicepa\Desktop\Mobile_SDK_projects
C:\Users\iodicepa\Desktop\Mobile_SDK_projects\myapp C:\Users\iodicepa\Desktop\Mo
bile_SDK_projects
Using cordova-fetch for cordova-android@6.2.3
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.paco.myapp
        Name: myapp
        Activity: MainActivity
        Android target: android-25
Subproject Path: CordovaLib
Android project created with cordova-android@6.2.3
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the pro
ject
Installing "cordova-plugin-whitelist" for android

               This plugin is only applicable for versions of cordova-android gr
eater than 4.0. If you have a previous platform version, you do *not* need this
plugin since the whitelist will be built in.

Saved plugin info for "cordova-plugin-whitelist" to config.xml
--save flag or autosave detected
Saving android@~6.2.3 into config.xml file ...
C:\Users\iodicepa\Desktop\Mobile_SDK_projects
C:\Users\iodicepa\Desktop\Mobile_SDK_projects\myapp C:\Users\iodicepa\Desktop\Mo
bile_SDK_projects
C:\Users\iodicepa\Desktop\Mobile_SDK_projects
forcedroid failed

Command failed: cordova plugin add https://github.com/forcedotcom/SalesforceMobi
leSDK-CordovaPlugin#v5.3.0 --force
Error: Failed to fetch plugin https://github.com/forcedotcom/SalesforceMobileSDK
-CordovaPlugin#v5.3.0 via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config -
-get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:204:12)
npm WARN addRemoteGit     at emitTwo (events.js:106:13)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit     at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit     at Socket.<anonymous> (internal/child_process.js:342:1
1)
npm WARN addRemoteGit     at emitOne (events.js:96:13)
npm WARN addRemoteGit     at Socket.emit (events.js:188:7)
npm WARN addRemoteGit     at Pipe._handle.close [as _onclose] (net.js:497:12)
npm WARN addRemoteGit  git+https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git#v5.3.0 resetting remote C:\Users\iodicepa\AppData\Roaming\npm-ca
che\_git-remotes\git-https-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlu
gin-git-v5-3-0-33807aab because of error: { Error: Command failed: git -c core.l
ongpaths=true config --get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:204:12)
npm WARN addRemoteGit     at emitTwo (events.js:106:13)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit     at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit     at Socket.<anonymous> (internal/child_process.js:342:1
1)
npm WARN addRemoteGit     at emitOne (events.js:96:13)
npm WARN addRemoteGit     at Socket.emit (events.js:188:7)
npm WARN addRemoteGit     at Pipe._handle.close [as _onclose] (net.js:497:12)
npm WARN addRemoteGit   killed: false,
npm WARN addRemoteGit   code: 1,
npm WARN addRemoteGit   signal: null,
npm WARN addRemoteGit   cmd: 'git -c core.longpaths=true config --get remote.ori
gin.url' }
npm ERR! git clone --template=C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-remotes\git-htt
ps-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v5-3-0-33807aab:
 Cloning into bare repository 'C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-
remotes\git-https-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v
5-3-0-33807aab'...
npm ERR! git clone --template=C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-remotes\git-htt
ps-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v5-3-0-33807aab:
 fatal: early EOF
npm ERR! git clone --template=C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-remotes\git-htt
ps-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v5-3-0-33807aab:
 fatal: The remote end hung up unexpectedly
npm ERR! git clone --template=C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-remotes\git-htt
ps-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v5-3-0-33807aab:
 fatal: index-pack failed
npm ERR! git clone --template=C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror https://github.com/forcedotcom/SalesforceMobileSDK-Co
rdovaPlugin.git C:\Users\iodicepa\AppData\Roaming\npm-cache\_git-remotes\git-htt
ps-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlugin-git-v5-3-0-33807aab:
 error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install" "https://github.com/forcedotcom/Sa
lesforceMobileSDK-CordovaPlugin#v5.3.0" "--save"
npm ERR! node v6.11.1
npm ERR! npm  v3.10.10
npm ERR! code 128

npm ERR! Command failed: git -c core.longpaths=true clone --template=C:\Users\io
dicepa\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror https://github
.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin.git C:\Users\iodicepa\AppData
\Roaming\npm-cache\_git-remotes\git-https-github-com-forcedotcom-SalesforceMobil
eSDK-CordovaPlugin-git-v5-3-0-33807aab
npm ERR! Cloning into bare repository 'C:\Users\iodicepa\AppData\Roaming\npm-cac
he\_git-remotes\git-https-github-com-forcedotcom-SalesforceMobileSDK-CordovaPlug
in-git-v5-3-0-33807aab'...
npm ERR! fatal: early EOF
npm ERR! fatal: The remote end hung up unexpectedly
npm ERR! fatal: index-pack failed
npm ERR! error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 1
0054
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\iodicepa\Desktop\Mobile_SDK_projects\myapp\node_modules\np
m-debug.log



I tried different cordova version as 6.2.0, 6.3.0, 6.4.0, 7.0.0 but i have the same error. i also tried with differed  connection.

Thanks in advance
Hi everyone,

I have to create a custom record list selectable to mass update a record field. 
I should be able to select multiple records and use a button/action to update a field.
I noticed that such a thing already exists for Leads in Sales Cloud. You can select multiple records and run an action:
Mass update

I'd like to build exactly the same thing.
Is it possible into a custom page to obtai the same result?
BEST REGARDS

Hi everyone,
I'd like to create a my own custom model. 
I did it using cURL without issues. Now I'm trying to get the same results using Javascript to have a token, create e datamodel, train a dataset ad have a prediction programmatically.
I'm having issues gettin a token from an ajax request.
This is my code to generate an assertion a get a token: 

function generate_assertion(sub, exp, privKey) {
            var header = JSON.stringify({
              "alg": "RS256",
              "typ": "JWT"
            });

            var timeInMillis = Math.round(+new Date() / 1000);
            exp = timeInMillis + (parseInt(exp) * 60);
            var domain = "https://api.dev.einstein.ai"
            

            var payload = {
              "sub": sub,
              "aud": domain + "/v1/oauth2/token",
              "exp": exp
            };
            assertion = KJUR.jws.JWS.sign(null, header, payload, privKey);
            var tokenPayload = {
              "assertion": assertion,
              "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer"
            };
            
            return tokenPayload;
      }
      
      
        // On form submit generate the access token
        function getToken() {
        
            var sub = 'iodicepasquale85@gmail.com';
            var exp = 7200;
            var tokenPayload = "";

            try {
            tokenPayload = generate_assertion(sub, exp, privKey);
            } catch (err) {
                console.log("ERROR: ", err);
            return;
            }

            $.ajax({
            type: 'post',
            url: 'https://api.einstein.ai/v1/oauth2/token',
            headers: 'Content-type : application/x-www-form-urlencoded',
            data: tokenPayload,
            success: function (data) {
                console.log("TOKEN: " , data["access_token"]);
            },
            error: function (data) {
                  console.log("ERROR: " , data);
            }    
            });
        }


Where "privKey" is the private key contained in the "predictive_services.pem" file I downloaded when I signed up for an account.

 "generate_assertion" Methos seems work fine. I'm having this ERROR in ajax request:

"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Best regards,
Pasquale

Hi everyone,

I have to create a custom record list selectable to mass update a record field. 
I should be able to select multiple records and use a button/action to update a field.
I noticed that such a thing already exists for Leads in Sales Cloud. You can select multiple records and run an action:
Mass update

I'd like to build exactly the same thing.
Is it possible into a custom page to obtai the same result?
BEST REGARDS

Hi everyone,
I'd like to create a my own custom model. 
I did it using cURL without issues. Now I'm trying to get the same results using Javascript to have a token, create e datamodel, train a dataset ad have a prediction programmatically.
I'm having issues gettin a token from an ajax request.
This is my code to generate an assertion a get a token: 

function generate_assertion(sub, exp, privKey) {
            var header = JSON.stringify({
              "alg": "RS256",
              "typ": "JWT"
            });

            var timeInMillis = Math.round(+new Date() / 1000);
            exp = timeInMillis + (parseInt(exp) * 60);
            var domain = "https://api.dev.einstein.ai"
            

            var payload = {
              "sub": sub,
              "aud": domain + "/v1/oauth2/token",
              "exp": exp
            };
            assertion = KJUR.jws.JWS.sign(null, header, payload, privKey);
            var tokenPayload = {
              "assertion": assertion,
              "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer"
            };
            
            return tokenPayload;
      }
      
      
        // On form submit generate the access token
        function getToken() {
        
            var sub = 'iodicepasquale85@gmail.com';
            var exp = 7200;
            var tokenPayload = "";

            try {
            tokenPayload = generate_assertion(sub, exp, privKey);
            } catch (err) {
                console.log("ERROR: ", err);
            return;
            }

            $.ajax({
            type: 'post',
            url: 'https://api.einstein.ai/v1/oauth2/token',
            headers: 'Content-type : application/x-www-form-urlencoded',
            data: tokenPayload,
            success: function (data) {
                console.log("TOKEN: " , data["access_token"]);
            },
            error: function (data) {
                  console.log("ERROR: " , data);
            }    
            });
        }


Where "privKey" is the private key contained in the "predictive_services.pem" file I downloaded when I signed up for an account.

 "generate_assertion" Methos seems work fine. I'm having this ERROR in ajax request:

"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Best regards,
Pasquale

Hello,

I need to connect to an external site to send objects. I use the code below but I still get an error ("wsse authentication" required) . 
Does somebody see the error?

Thank you for your help!
 
        String jsonLeads = JSON.serialize(leadToSend);        
        String headerReq = createHeader();
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization',headerReq);
        system.debug('header '+request.getHeader('Authorization'));
        request.setEndpoint('http://xxxx');
        request.setMethod('POST');
        request.setBody(jsonLeads);
        system.debug('request '+request);
        
        try{
            HttpResponse response = http.send(request);
            if (response.getStatusCode() != 201) {
                System.debug('The status code returned was not expected: ' +
                             response.getStatusCode() + ' ' + response.getStatus()+response.getBody());
            } else {
                System.debug(response.getBody());
            }
        }catch(System.CalloutException e) {
            system.debug(e);
        }       
    }
    
    public static String createHeader(){
        String token = 'xxxxxx';
        String chars = '0123456789abcdef';
        String nonce = '';
        String dt = system.now()+'Z';
        
        while (nonce.length() < 32) {
            Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
            nonce += chars.substring(idx, idx+1);
        }
        system.debug('nonce: '+nonce);
        String nonce64 = EncodingUtil.base64Encode(Blob.valueOf(nonce));
        
        Blob target = Blob.valueOf(nonce+dt+token); 
        Blob digestSha1 = Crypto.generateDigest('SHA1',target);
        String digest = EncodingUtil.base64Encode(digestSha1);
        
        String header = 'X-WSSE:UsernameToken Token="'+token+'",PasswordDigest="'+digest+'",Nonce="'+nonce64+'",Created="'+dt+'"';       
        return header;
    }