Skip to content

Instantly share code, notes, and snippets.

@tstachl tstachl/create_contact.js
Last active Jul 13, 2016

Embed
What would you like to do?
Salesforce Snippet - Allows you to create a contact for an account by domain matching.
/**
* USAGE Information
* 1. open the developer tools for a salesforce classic site
* 2. copy and paste the code of this snippet into the console
* 3. `createFromEmail('John Snow <john@nightswatch.com>').
*
* WHAT does the script do?
* 1. it parses the email string into name and email address
* 2. it runs an API search for an account with the website `https://www.nightswatch.com/`
* 3. it splits the name part `John Snow` into firstname and lastname
* 4. it creates a contact with the first and lastname as well as the email address for the account
*/
/*emailaddress*/!function(a){"use strict";function b(a){function b(){return ya>xa}function c(){return wa[xa]}function d(){return xa}function f(a){xa=a}function g(){xa+=1}function h(){xa=0,ya=wa.length}function i(a,b){return{name:a,tokens:b||"",semantic:b||"",children:[]}}function j(a,b){var c;return null===b?null:(c=i(a),c.tokens=b.tokens,c.semantic=b.semantic,c.children.push(b),c)}function k(a,b){return null!==b&&(a.tokens+=b.tokens,a.semantic+=b.semantic),a.children.push(b),a}function l(a){var d;return b()?(d=c(),a(d)?(g(),i("token",d)):null):null}function m(a){return function(){return j("literal",l(function(b){return b===a}))}}function n(){var a=arguments;return function(){var b,c,e,g;for(g=d(),c=i("and"),b=0;b<a.length;b+=1){if(e=a[b](),null===e)return f(g),null;k(c,e)}return c}}function o(){var a=arguments;return function(){var b,c,e;for(e=d(),b=0;b<a.length;b+=1){if(c=a[b](),null!==c)return c;f(e)}return null}}function p(a){return function(){var b,c;return c=d(),b=a(),null!==b?b:(f(c),i("opt"))}}function q(a){return function(){var b=a();return null!==b&&(b.semantic=""),b}}function r(a){return function(){var b=a();return null!==b&&b.semantic.length>0&&(b.semantic=" "),b}}function s(a,b){return function(){var c,e,g,h,j;for(h=d(),c=i("star"),g=0,j=void 0===b?0:b;null!==(e=a());)g+=1,k(c,e);return g>=j?c:(f(h),null)}}function t(a){function b(a){return" "===a||" "===a||"\r"===a||"\n"===a}var c,d;for(d="",c=0;c<a.length;c+=1)b(a[c])&&b(a[c+1])||(d+=a[c]);return b(d[0])&&(d=d.substring(1)),b(d[d.length-1])&&(d=d.substring(0,d.length-1)),d}function u(a){return a.charCodeAt(0)>=128}function v(){return j("cr",m("\r")())}function w(){return j("crlf",n(v,z)())}function x(){return j("dquote",m('"')())}function y(){return j("htab",m(" ")())}function z(){return j("lf",m("\n")())}function A(){return j("sp",m(" ")())}function B(){return j("vchar",l(function(b){var c=b.charCodeAt(0),d=c>=33&&126>=c;return a.rfc6532&&(d=d||u(b)),d}))}function C(){return j("wsp",o(A,y)())}function D(){var a=j("quoted-pair",o(n(m("\\"),o(B,C)),ha)());return null===a?null:(a.semantic=a.semantic[1],a)}function E(){return j("fws",o(ja,n(p(n(s(C),q(w))),s(C,1)))())}function F(){return j("ctext",o(function(){return l(function(b){var c=b.charCodeAt(0),d=c>=33&&39>=c||c>=42&&91>=c||c>=93&&126>=c;return a.rfc6532&&(d=d||u(b)),d})},fa)())}function G(){return j("ccontent",o(F,D,H)())}function H(){return j("comment",n(m("("),s(n(p(E),G)),p(E),m(")"))())}function I(){return j("cfws",o(n(s(n(p(E),H),1),p(E)),E)())}function J(){return j("atext",l(function(b){var c=b>="a"&&"z">=b||b>="A"&&"Z">=b||b>="0"&&"9">=b||["!","#","$","%","&","'","*","+","-","/","=","?","^","_","`","{","|","}","~"].indexOf(b)>=0;return a.rfc6532&&(c=c||u(b)),c}))}function K(){return j("atom",n(r(p(I)),s(J,1),r(p(I)))())}function L(){var a,b;return a=j("dot-atom-text",s(J,1)()),null===a?a:(b=s(n(m("."),s(J,1)))(),null!==b&&k(a,b),a)}function M(){return j("dot-atom",n(q(p(I)),L,q(p(I)))())}function N(){return j("qtext",o(function(){return l(function(b){var c=b.charCodeAt(0),d=33===c||c>=35&&91>=c||c>=93&&126>=c;return a.rfc6532&&(d=d||u(b)),d})},ga)())}function O(){return j("qcontent",o(N,D)())}function P(){return j("quoted-string",n(q(p(I)),q(x),s(n(p(r(E)),O)),p(q(E)),q(x),q(p(I)))())}function Q(){return j("word",o(K,P)())}function R(){return j("phrase",o(ia,s(Q,1))())}function S(){return j("address",o(T,W)())}function T(){return j("mailbox",o(U,da)())}function U(){return j("name-addr",n(p(X),V)())}function V(){return j("angle-addr",o(n(q(p(I)),m("<"),da,m(">"),q(p(I))),ka)())}function W(){return j("group",n(X,m(":"),p($),m(";"),q(p(I)))())}function X(){return j("display-name",function(){var a=R();return null!==a&&(a.semantic=t(a.semantic)),a}())}function Y(){return j("mailbox-list",o(n(T,s(n(m(","),T))),na)())}function Z(){return j("address-list",o(n(S,s(n(m(","),S))),oa)())}function $(){return j("group-list",o(Y,q(I),pa)())}function _(){return j("local-part",o(qa,M,P)())}function aa(){return j("dtext",o(function(){return l(function(b){var c=b.charCodeAt(0),d=c>=33&&90>=c||c>=94&&126>=c;return a.rfc6532&&(d=d||u(b)),d})},sa)())}function ba(){return j("domain-literal",n(q(p(I)),m("["),s(n(p(E),aa)),p(E),m("]"),q(p(I)))())}function ca(){return j("domain",function(){var b=o(ra,M,ba)();return a.rejectTLD&&b.semantic.indexOf(".")<0?null:b}())}function da(){return j("addr-spec",n(_,m("@"),ca)())}function ea(){return a.strict?null:j("obs-NO-WS-CTL",l(function(a){var b=a.charCodeAt(0);return b>=1&&8>=b||11===b||12===b||b>=14&&31>=b||127===b}))}function fa(){return a.strict?null:j("obs-ctext",ea())}function ga(){return a.strict?null:j("obs-qtext",ea())}function ha(){return a.strict?null:j("obs-qp",n(m("\\"),o(m("\x00"),ea,z,v))())}function ia(){return a.strict?null:j("obs-phrase",n(Q,s(o(Q,m("."),r(I))))())}function ja(){return a.strict?null:j("obs-FWS",s(n(q(p(w)),C),1)())}function ka(){return a.strict?null:j("obs-angle-addr",n(q(p(I)),m("<"),la,da,m(">"),q(p(I)))())}function la(){return a.strict?null:j("obs-route",n(ma,m(":"))())}function ma(){return a.strict?null:j("obs-domain-list",n(s(o(q(I),m(","))),m("@"),ca,s(n(m(","),q(p(I)),p(n(m("@"),ca)))))())}function na(){return a.strict?null:j("obs-mbox-list",n(s(n(q(p(I)),m(","))),T,s(n(m(","),p(n(T,q(I))))))())}function oa(){return a.strict?null:j("obs-addr-list",n(s(n(q(p(I)),m(","))),S,s(n(m(","),p(n(S,q(I))))))())}function pa(){return a.strict?null:j("obs-group-list",n(s(n(q(p(I)),m(",")),1),q(p(I)))())}function qa(){return a.strict?null:j("obs-local-part",n(Q,s(n(m("."),Q)))())}function ra(){return a.strict?null:j("obs-domain",n(K,s(n(m("."),K)))())}function sa(){return a.strict?null:j("obs-dtext",o(ea,D)())}function ta(a,b){var c,d,e;if(null===b||void 0===b)return null;for(d=[b];d.length>0;){if(e=d.shift(),e.name===a)return e;for(c=0;c<e.children.length;c+=1)d.push(e.children[c])}return null}function ua(a,b){var c,d,e,f;if(null===b||void 0===b)return null;for(d=[b],f=[];d.length>0;)for(e=d.shift(),e.name===a&&f.push(e),c=0;c<e.children.length;c+=1)d.push(e.children[c]);return f}function va(b){function c(a){return null!==a?a.semantic:null}var d,e,f,g,h,i,j,k;if(null===b)return null;for(e={ast:b},f=ua("address",b),e.addresses=[],d=0;d<f.length;d+=1)g=f[d],h=ta("display-name",g),i=ta("addr-spec",g),j=ta("local-part",i),k=ta("domain",i),e.addresses.push({node:g,parts:{name:h,address:i,local:j,domain:k},name:c(h),address:c(i),local:c(j),domain:c(k)});if(a.simple)for(e=e.addresses,d=0;d<e.length;d+=1)delete e[d].node;return e}var wa,xa,ya,za;if(a=e(a,{}),null===a)return null;if(wa=a.input,!a.strict){if(h(),a.strict=!0,za=Z(wa),a.partial||!b())return va(za);a.strict=!1}return h(),za=Z(wa),!a.partial&&b()?null:va(za)}function c(a){var c;return a=e(a,{rfc6532:!0,simple:!0}),null===a?null:(c=b(a),!c||!a.partial&&a.simple&&c.length>1||!a.simple&&c.addresses.length>1?null:a.simple?c&&c[0]:c&&c.addresses&&c.addresses[0])}function d(a){var c;return a=e(a,{rfc6532:!0,simple:!0}),null===a?null:(c=b(a),a.simple?c:c.addresses)}function e(a,b){function c(a){return"[object String]"===Object.prototype.toString.call(a)}function d(a){return a===Object(a)}function e(a){return null===a||void 0===a}var f,g;if(c(a))a={input:a};else if(!d(a))return null;if(!c(a.input))return null;if(!b)return null;f={rfc6532:!1,partial:!1,simple:!1,strict:!1,rejectTLD:!1};for(g in f)e(a[g])&&(a[g]=e(b[g])?f[g]:b[g]),a[g]=!!a[g];return a}b.parseOneAddress=c,b.parseAddressList=d,"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=b:a.emailAddresses=b}(this);
/*superagent*/!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.superagent=t()}}(function(){return function t(e,r,i){function n(o,a){if(!r[o]){if(!e[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var h=new Error("Cannot find module '"+o+"'");throw h.code="MODULE_NOT_FOUND",h}var c=r[o]={exports:{}};e[o][0].call(c.exports,function(t){var r=e[o][1][t];return n(r?r:t)},c,c.exports,t,e,r,i)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<i.length;o++)n(i[o]);return n}({1:[function(t,e,r){function i(t){return null!==t&&"object"==typeof t}e.exports=i},{}],2:[function(t,e,r){var i=t("./is-object");r.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},r.parse=function(t){return this._parser=t,this},r.serialize=function(t){return this._serializer=t,this},r.timeout=function(t){return this._timeout=t,this},r.then=function(t,e){if(!this._fullfilledPromise){var r=this;this._fullfilledPromise=new Promise(function(t,e){r.end(function(r,i){r?e(r):t(i)})})}return this._fullfilledPromise.then(t,e)},r.use=function(t){return t(this),this},r.get=function(t){return this._header[t.toLowerCase()]},r.getHeader=r.get,r.set=function(t,e){if(i(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},r.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},r.field=function(t,e){return this._getFormData().append(t,e),this},r.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},r.withCredentials=function(){return this._withCredentials=!0,this},r.redirects=function(t){return this._maxRedirects=t,this},r.toJSON=function(){return{method:this.method,url:this.url,data:this._data}},r._isHost=function(t){var e={}.toString.call(t);switch(e){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}},r.send=function(t){var e=i(t),r=this._header["content-type"];if(e&&i(this._data))for(var n in t)this._data[n]=t[n];else"string"==typeof t?(r||this.type("form"),r=this._header["content-type"],"application/x-www-form-urlencoded"==r?this._data=this._data?this._data+"&"+t:t:this._data=(this._data||"")+t):this._data=t;return!e||this._isHost(t)?this:(r||this.type("json"),this)}},{"./is-object":1}],3:[function(t,e,r){function i(t,e,r){return"function"==typeof r?new t("GET",e).end(r):2==arguments.length?new t("GET",e):new t(e,r)}e.exports=i},{}],4:[function(t,e,r){function i(t){return t?n(t):void 0}function n(t){for(var e in i.prototype)t[e]=i.prototype[e];return t}"undefined"!=typeof e&&(e.exports=i),i.prototype.on=i.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},i.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},i.prototype.off=i.prototype.removeListener=i.prototype.removeAllListeners=i.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i,n=0;n<r.length;n++)if(i=r[n],i===e||i.fn===e){r.splice(n,1);break}return this},i.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks["$"+t];if(r){r=r.slice(0);for(var i=0,n=r.length;n>i;++i)r[i].apply(this,e)}return this},i.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},i.prototype.hasListeners=function(t){return!!this.listeners(t).length}},{}],5:[function(t,e,r){e.exports=function(t,e,r){for(var i=0,n=t.length,s=3==arguments.length?r:t[i++];n>i;)s=e.call(null,s,t[i],++i,t);return s}},{}],6:[function(t,e,r){function i(){}function n(t){if(!b(t))return t;var e=[];for(var r in t)null!=t[r]&&s(e,r,t[r]);return e.join("&")}function s(t,e,r){if(Array.isArray(r))return r.forEach(function(r){s(t,e,r)});if(b(r))for(var i in r)s(t,e+"["+i+"]",r[i]);else t.push(encodeURIComponent(e)+"="+encodeURIComponent(r))}function o(t){for(var e,r,i={},n=t.split("&"),s=0,o=n.length;o>s;++s)e=n[s],r=e.indexOf("="),-1==r?i[decodeURIComponent(e)]="":i[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return i}function a(t){var e,r,i,n,s=t.split(/\r?\n/),o={};s.pop();for(var a=0,u=s.length;u>a;++a)r=s[a],e=r.indexOf(":"),i=r.slice(0,e).toLowerCase(),n=w(r.slice(e+1)),o[i]=n;return o}function u(t){return/[\/+]json\b/.test(t)}function h(t){return t.split(/ *; */).shift()}function c(t){return m(t.split(/ *; */),function(t,e){var r=e.split(/ *= */),i=r.shift(),n=r.shift();return i&&n&&(t[i]=n),t},{})}function l(t,e){e=e||{},this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this._setStatusProperties(this.xhr.status),this.header=this.headers=a(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function p(t,e){var r=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new l(r)}catch(i){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=i,t.rawResponse=r.xhr&&r.xhr.responseText?r.xhr.responseText:null,t.statusCode=r.xhr&&r.xhr.status?r.xhr.status:null,r.callback(t)}if(r.emit("response",e),t)return r.callback(t,e);try{if(e.status>=200&&e.status<300)return r.callback(t,e);var n=new Error(e.statusText||"Unsuccessful HTTP response");n.original=t,n.response=e,n.status=e.status,r.callback(n,e)}catch(i){r.callback(i)}})}function f(t,e){var r=v("DELETE",t);return e&&r.end(e),r}var d,y=t("emitter"),m=t("reduce"),_=t("./request-base"),b=t("./is-object");d="undefined"!=typeof window?window:"undefined"!=typeof self?self:this;var v=e.exports=t("./request").bind(null,p);v.getXHR=function(){if(!(!d.XMLHttpRequest||d.location&&"file:"==d.location.protocol&&d.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}return!1};var w="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};v.serializeObject=n,v.parseString=o,v.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},v.serialize={"application/x-www-form-urlencoded":n,"application/json":JSON.stringify},v.parse={"application/x-www-form-urlencoded":o,"application/json":JSON.parse},l.prototype.get=function(t){return this.header[t.toLowerCase()]},l.prototype._setHeaderProperties=function(t){var e=this.header["content-type"]||"";this.type=h(e);var r=c(e);for(var i in r)this[i]=r[i]},l.prototype._parseBody=function(t){var e=v.parse[this.type];return!e&&u(this.type)&&(e=v.parse["application/json"]),e&&t&&(t.length||t instanceof Object)?e(t):null},l.prototype._setStatusProperties=function(t){1223===t&&(t=204);var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.clientError=4==e,this.serverError=5==e,this.error=4==e||5==e?this.toError():!1,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.notFound=404==t,this.forbidden=403==t},l.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,i="cannot "+e+" "+r+" ("+this.status+")",n=new Error(i);return n.status=this.status,n.method=e,n.url=r,n},v.Response=l,y(p.prototype);for(var x in _)p.prototype[x]=_[x];p.prototype.type=function(t){return this.set("Content-Type",v.types[t]||t),this},p.prototype.responseType=function(t){return this._responseType=t,this},p.prototype.accept=function(t){return this.set("Accept",v.types[t]||t),this},p.prototype.auth=function(t,e,r){switch(r||(r={type:"basic"}),r.type){case"basic":var i=btoa(t+":"+e);this.set("Authorization","Basic "+i);break;case"auto":this.username=t,this.password=e}return this},p.prototype.query=function(t){return"string"!=typeof t&&(t=n(t)),t&&this._query.push(t),this},p.prototype.attach=function(t,e,r){return this._getFormData().append(t,e,r||e.name),this},p.prototype._getFormData=function(){return this._formData||(this._formData=new d.FormData),this._formData},p.prototype.callback=function(t,e){var r=this._callback;this.clearTimeout(),r(t,e)},p.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},p.prototype._timeoutError=function(){var t=this._timeout,e=new Error("timeout of "+t+"ms exceeded");e.timeout=t,this.callback(e)},p.prototype._appendQueryString=function(){var t=this._query.join("&");t&&(this.url+=~this.url.indexOf("?")?"&"+t:"?"+t)},p.prototype.end=function(t){var e=this,r=this.xhr=v.getXHR(),n=this._timeout,s=this._formData||this._data;this._callback=t||i,r.onreadystatechange=function(){if(4==r.readyState){var t;try{t=r.status}catch(i){t=0}if(0==t){if(e.timedout)return e._timeoutError();if(e._aborted)return;return e.crossDomainError()}e.emit("end")}};var o=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),t.direction="download",e.emit("progress",t)};this.hasListeners("progress")&&(r.onprogress=o);try{r.upload&&this.hasListeners("progress")&&(r.upload.onprogress=o)}catch(a){}if(n&&!this._timer&&(this._timer=setTimeout(function(){e.timedout=!0,e.abort()},n)),this._appendQueryString(),this.username&&this.password?r.open(this.method,this.url,!0,this.username,this.password):r.open(this.method,this.url,!0),this._withCredentials&&(r.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof s&&!this._isHost(s)){var h=this._header["content-type"],c=this._serializer||v.serialize[h?h.split(";")[0]:""];!c&&u(h)&&(c=v.serialize["application/json"]),c&&(s=c(s))}for(var l in this.header)null!=this.header[l]&&r.setRequestHeader(l,this.header[l]);return this._responseType&&(r.responseType=this._responseType),this.emit("request",this),r.send("undefined"!=typeof s?s:null),this},v.Request=p,v.get=function(t,e,r){var i=v("GET",t);return"function"==typeof e&&(r=e,e=null),e&&i.query(e),r&&i.end(r),i},v.head=function(t,e,r){var i=v("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.options=function(t,e,r){var i=v("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.del=f,v["delete"]=f,v.patch=function(t,e,r){var i=v("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.post=function(t,e,r){var i=v("POST",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.put=function(t,e,r){var i=v("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i}},{"./is-object":1,"./request":3,"./request-base":2,emitter:4,reduce:5}]},{},[6])(6)});
(function(global) {
function createFromEmail(email) {
var sid = getCookie('sid');
var email = emailAddresses.parseOneAddress(email);
superagent
.get('/services/data/v20.0/query')
.set('Authorization', 'Bearer ' + sid)
.query({ q: "Select Id, Name, Website From Account Where Website Like '%" + email.domain + "%'" })
.end(function(err, res) {
console.log(err, res);
if (err) return alert(err.message);
try {
var accountId = res.body.records[0].Id;
var nameParts = email.name.split(' ');
var lastName = nameParts.pop();
var firstName = nameParts.join(' ');
superagent
.post('/services/data/v20.0/sobjects/Contact')
.set('Authorization', 'Bearer ' + sid)
.send({
'FirstName': firstName,
'LastName': lastName,
'Email': email.address,
'AccountId': res.body.records[0].Id
})
.end(function(err, res) {
console.log(err, res);
});
} catch(err) {
alert(err.message);
}
});
}
global.createFromEmail = createFromEmail;
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.