SFDC Integration:
SFDC Integration
What is SOAP Integration ?
Simple Object Access rotocol !SOA" is a stanar protocol specification specification for message e$c%ange base on &'() Communication bet*een t%e *eb ser+ice an client %appens using &'( messages) SOA efines t%e rules for communication li,e *%at are all t%e tags t%at s%oul be use in &'( an t%eir meaning) What is REST?
-.S/ful *eb ser+ice uses arc%itectures t%at use 0// or similar protocolsb1 restricting t%e interface to use stanar operations li,e ./3 OS/3 /3 D.(./. for 0//)
Salesforce)com5s Salesforce)com5s uniue multitenant arc%itecture7in *%ic% all users an applications s%are a single3 common infrastructure an coe base t%at is centrall1 maintaine7is t%e ,e1 to creating integrations t%at on5t brea,) /%e Force)com multitenant platform3 t%e Force)com eb Ser+ices AI3 an a *ie net*or, of integration partners come toget%er to pro+ie -api time to +alue3Simplicit13 Fle$ibilit1 an c%oice an pro+en success an preictabilit1 as benefits) Salesforce robust integration capabilities gi+e a free %an to t%e Aministrators9De+elopers Aministrators9De+elopers to buil t%e integration in mainl1 t*o *a1s t%at are SOA an -.S/ AIs) When to use SOAP API ?
se SOA AI to create3 retrie+e3 upate or elete recors3 suc% as accounts3 leas3 an custom objects) it% more t%an 2 ifferent calls3 SOA AI also allo*s 1ou to maintain pass*ors3 perform searc%es3 an muc% more) se SOA AI in an1 language t%at supports eb ser+ices) When to Use REST API ?
-.S/ AI pro+ies a po*erful3 con+enient3 an simple -.S/;base eb ser+ices interface for interacting *it% Salesforce) Its a+antages inclue ease of integration an e+elopment3 an it5s an e$cellent c%oice of tec%nolog1 for use *it% mobile applications an eb projects) 0o*e+er3 if 1ou %a+e a large number of recors to process3 1ou ma1 *is% to t o use
CA(( I>S
Call Ins I)
.$t s1stem to Salesforce Integration using SOA AI)
Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
System defined WSDLs: Enterprise WSDLs: It is strongl1 t1pe an It pro+ies informationabout 1our sc%ema3 ata t1pes3
an fiels to 1our e+elopment en+ironment3 allo*ing for a tig%ter integration bet*een itan t%e Force)com eb ser+ice) >ote t%e follo*ing *%en generating t%e enterprise SD(: ?) If ne* custom fiels or objects are ae to3 rename3 or remo+e from 1our organi=ation5s information3 1ou nee to regenerate t%e SD( file in orer to access t%em) 2) /%e generate SD( contains t%e objects an fiels in 1our organi=ation3 incluing t%ose a+ailable in t%e selecte +ersions of eac% installe pac,age) If a fiel or object is ae in a later pac,age +ersion3 1ou must generate t%e enterprise SD( *it% t%at pac,age +ersion to *or, *it% t%e object or fiel in 1our AI integration)
Partner WSDLs:
/%is AI is for salesforce)com partners *%o are e+eloping client applications for multiple organi=ations) As a loosel1;t1pe representation of t%e Salesforce object moel3 t%e partner SD( can be use to access ata *it%in an1 organi=ation) User defined WSDLs:
.nterprise SD( or artner SD( is use to perform basic Create3 -ea3 an pate or Delete operations on sObjects) If reuirement is more comple$ t%an mere @uer1 or upate an object recor3 Salesforce %as gi+en a facilit1 to t%e De+elopers to generate t%eir o*n
Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
Sample .$ample for user efine SD(:
global class SpecialAccounts global class AccountInfo *ebSer+ice String Acct>ameG *ebSer+ice Integer Acct>umberG H *ebSer+ice static Account createAccount!AccountInfo info" Account acct ne* Account!"G acct)>ame info)Acct>ameG acct)Account>umber String)+alueOf!info)Acct>umber"G insert acctG return acctG H *ebSer+ice static I JK createAccounts!Account parent3 Account c%il3 Account granC%il" insert parentG c%il)parentI parent)IG insert c%ilG granC%il)parentI c%il)IG insert granC%ilG I JK results ne* IJKG resultsJK parent)IG resultsJ?K c%il)IG resultsJ2K granC%il)IG return resultsG H H
/ips or Suggestions for CA(( I> SOA Integration: ?) An1 *eb ser+ices t%at are gi+en b1 SFDC e+eloper to .$ternal s1stem5s e+elopers s%oul be pro+ie along *it% Sample -euest an -esponse) For stanar9s1stem efine *sls please fin t%e belo* lin, *%ere SFDC pro+ies all sample reuests an responses) %ttp:99*i,i)e+eloperforce)com9page9SampleLSOAL'essagesLM28?)LAIM2N)
Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
2) Since user efine SD(s are generate for +er1 specific reuirement 3 it is our ut1 to generate sample reuests9responses3 to o so 3 just consume t%e *sl into SOA I tool an c%ec, %o* a sample reuest loo,s li,e an *%at inputs are reuire for t%e ser efine *sl) Since *e alrea1 ,no* from *%at Ape$ class t%is *eb ser+ice is generate *e s%oul be in a position to recogni=e t%e reuire inputs) Once t%e inputs are gi+en perform run operation *%ic% gi+es 1ou sample response for t%e sample reuest) Cop1 bot% reuest an response an enclose bot% *it% eb ser+ice t%at is generate b1 Ape$ class t%en s%are t%em to t%e e$ternal person)
II)
.$t s1stem to Sales force Integration using -.S/ AI As %o* an1 ape$ class can be e$pose as *ebser+ices *it% ebSer+ice5 ,e1 *or in a similar *a1 *e can also e$pose an1 class as -est ser+ice using @RestResource5) Sample coe for -est Integration in CA(( In is belo*3 -est-esource!url'apping9Account9P" global *it% s%aring class '1-est-esource 0ttpDelete global static +oi oDelete!" -est-euestre -estConte$t)reuestG -est-esponse res -estConte$t)responseG String accountI re)reuest-I)substring!re)reuest-I)lastIne$Of!9"Q?"G Account account JS.(.C/ I F-O' Account 0.-. I :accountIKG elete accountG H 0ttpet global static Account oet!" -est-euestre -estConte$t)reuestG -est-esponse res -estConte$t)responseG String accountI re)reuest-I)substring!re)reuest-I)lastIne$Of!9"Q?"G Account result JS.(.C/ I3 >ame3 %one3 ebsite F-O' Account 0.-. I :accountIKG return resultG H 0ttpost global static String oost!String name3 String p%one3 String *ebsite" s1stem)ebug!%ere is t%e name Qname"G Account account ne* Account!"G account)>ame nameG account)p%one p%oneG account)*ebsite *ebsiteG insert accountG return account)IG H H Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
/ips or Consierations in -.S/ Integration) ?) se apigee)com or or,benc%)e+eloperforce)com *%ile c%ec,ing t%e -.S/ resources) 2) %ile *riting coe for rest integration all rea operations s%oul be *ritten in a met%o *%ic% is e$pose9prefi$e *it% 0ttpet for better securit1 an *rite operations s%oul be e$pose as 0ttpost annotation)
CA(( O/S
III)
Calling .$ternal s1stem from SFDC using SOA Integration ?) Con+ert t%e SD( to ape$ class !Set up De+elop ; R Ape$ Class ;R enerate from SD(" nerstan t%e generate ape$ class ; %ic% one is responsible for login met%o3 reuest class3 response class an t%e original calling met%o) 2) Ape$ class9trigger to e$ecute 1our logic; On button clic, I *ant to call t%e e$ternal *eb ser+ice) 0ence3 ) Create a custom button an open a F page on clic, of t%is custom button3 t%is F page *ill be associate to t%e ape$ class 4) A t%e remote site setting for t%e en point -( gi+en
After a class is generate from SD(3 just pa1 attention to on reuire met%os3 nee not to unerstan t%e entire coe) .+er1 name space in t%e SD( *ill be con+erte as a class3 e+er1 element in SD( *ill be con+erte as a propert1 an eac% operation in SD( is going to be a met%o in Ape$ class) /o unerstan in a better *a1 it is a+isable to first c%ec, in SOA I an perform intene operations t%en consume in SFDC) Once t%e class is generate tr1 to see *%et%er class contains an1 login met%os !%ere *e are going to use open source SD( *%ic% %as no login met%o") If so create a instance to t%e class in *%ic% login met%o is present an call t%e met%o on t%at instance) After login response sa1s successful connection3 perform t%e intene operations b1 calling t%e met%os on alrea1 create instance)
0ere is t%e e$ample to get t%e . 2?2 etails *%ic% is e$pose as eb ser+ices) (in, to SD( is %ere :%ttp:99footballpool)ataaccess)eu9ata9info)*soTSD( Consume t%e SD( as mentione abo+e it generates t%e reuire classes) Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
/o call t%e abo+e class *rite anot%er class as belo*3 sample coe is belo*))
public *it% s%aring class controllerLIn+o,eLfoot
public string JK efeners(ist getGsetGH public string JK teamFor*ars(ist getGsetGH public string JK teamoalUeepers(ist getGsetGH public string JK team'ifiels(ist getGsetGH 99public String JK goalUeepersG
public controllerLIn+o,eLfoot
public +oi eu2?2 !" footballpoolDataaccess.u)InfoSoap ret ne* footballpoolDataaccess.u)InfoSoap !"G noOfCars ret)roupCount!"G s1stem)ebug!/otal roups RR QnoOfCars "G
footballpoolDataaccess.u)Arra1OfStringalloalUeepers ne* footballpoolDataaccess.u)Arra1OfString !"G alloalUeepers ret)AlloalUeepers!countr1"G goalUeepers alloalUeepers)stringL$G 99 s1stem)ebug!/otal oal Ueepers RR QgoalUeepers"G getO+erall/eamInfo!countr1"G H public +oi getroupCompInfo !String poul" footballpoolDataaccess.u)InfoSoap ret ne* footballpoolDataaccess.u)InfoSoap !"G footballpoolDataaccess.u)Arra1Oft/eamInfocomp(ist ret)roupCompetitors!poul"G Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
eac%/eamInfo comp(ist)t/eamInfoG s1stem)ebug!%ere is t%e roup AVs /eams WWWQeac%/eamInfo"G H public +oi getO+erall/eamInfo !String countr1" footballpoolDataaccess.u)InfoSoap ret ne* footballpoolDataaccess.u)InfoSoap !"G footballpoolDataaccess.u)InfoSoap/eamInfo-es ne* footballpoolDataaccess.u)InfoSoap !"G footballpoolDataaccess.u)tFull/eamInfoteam'embers(ist ret)Full/eamInfo!countr1"G footballpoolDataaccess.u)Arra1OfString efeners team'embers(ist)sDefenersG footballpoolDataaccess.u)Arra1OfStringteamFor*ars team'embers(ist)sFor*arsG footballpoolDataaccess.u)Arra1OfStringteamoalUeepers team'embers(ist)soalUeepersG footballpoolDataaccess.u)Arra1OfStringteam'ifiels team'embers(ist)s'iFielsG efeners(ist efeners)stringL$G teamFor*ars(ist teamFor*ars)stringL$G teamoalUeepers(ist teamoalUeepers)stringL$G team'ifiels(ist team'ifiels)stringL$G
s1stem)ebug!%ere is t%e /eam reeceVs efeners list WWWQteam'embers(ist)sDefeners"G
H H
I)
Calling e$ternal s1stem from SFDC using -.S/ AI
Sample coe for -.S/ AI *it% XSO> parsing) public *it% s%aring class controllerLrestApiLgeoIp public String ipAressgetGsetGH public string location getGsetGH public string ret getGsetGH public string resString getGsetGH public booleanrenerFiel setGgetGH ublic (istYStringRfiel>ame getGsetGH ublic (istYStringRfielalueG
public +oi sa+e !" fiel>ame ne* listYStringR !"G %ttp-euestre ne* %ttpreuest !"G re)setenpoint!%ttp:99freegeoip)net9json9QipAress"G re)setmet%o!./"G s1stem)ebug!%ttp:99freegeoip)net9json9QipAress"G %ttp %t ne* %ttp !"G Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
%ttpresponse res %t)sen!re"G resString res)getbo1!"G s1stem)ebug!res)getbo1!""G XSO>arser parser XSO>)createparser!res)getbo1!""G *%ile!parser)ne$t/o,en!" Z null" if!parser)getCurrent/o,en!" XSO>/o,en)FI.(DL>A'." 99parser)ne$t/o,en!"G ret parser)get/e$t!"G parser)ne$t/o,en!"G ret retQ:: Q parser)get/e$t!"G fiel>ame)a!ret"G 99parser)ne$talue!"G s1stem)ebug!%ere is t%e fielname [[[[[[[PPPP[[[[[[ Qret"G H 99 String str parser)get/e$t!"G 99 alueDict)a!a"G A(.LS/-I> H H H
eneral Consierations in integrations: ?) In real time scenarios aut%entication of e$ternal s1stem !login creentials" nee to be pro+ie in Ape$ classes *%ile Call outs irrespecti+e of -.S/ or SOA) Since De+9/est9ro sanbo$es s%oul connect t%eir respecti+e e$ternal s1stem counterparts *e cannot %arcoe t%e creentials in ape$ classes ue to t%e fact t%at once /est coe %as been mo+e to -OD *e cannot moif1 t%e Ape$ class to c%ange creentials from /est to ro) In orer to accomplis% t%is use Custom settings or Custom labels to sa+e t%e creentials of t%e .$ternal s1stem in eac% sanbo$ accoringl1 an ,eep call t%e custom settings9(abels all t%e time from Ape$ class) .nsure t%at ro sanbo$ *ill %a+e its5 e$ternal s1stem Creentials to be sa+e in Custom settings3 same case *it% De+ an /est)
Inboun .mail e$ample: global class SampleCreateContact.mail.$ample implements 'essaging)Inboun.mail0anler global Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
'essaging)Inboun.mail-esult%anleInboun.mail!'essaging)inboun.mailemail3'essaging)Inbou n.n+elopeen+" 'essaging)Inboun.mail-esult result ne* 'essaging)Inboun.mail-esult!"G Contact contObj ne* Contact!"G tr1 contObj Jselect i3 email3 SubjectLLc3 .mailLameG contObj)email email)fromAressG contObj)SubjectLLc email)subjectG contObj).mailLame t$tAttac%ment)file>ameG attac%ment)ame binar1Attac%ment)file>ameG attac%ment)
SFDC Integration:
Outboun .mail: sing 'essaging interface3 *e can configure t%e s1stem to sen an emails to t%e customers9users or *%omsoe+er nee to be notifie) Email Administration > Organization-Wide Email Addresses an create ne* email aress) e can uer1 t%e Org *ie email aress in ape$ coe as belo*))
'essaging)reser+eSingle.mailCapacit1!2"G 'essaging)Single.mail'essage mail ne* 'essaging)Single.mail'essage!"G
StringJK toAresses ne* StringJK pa+an),alapatapuge)comHG StringJK ccAresses ne* StringJK pa+an),alapatapuge)comHG
99 Assign t%e aresses for t%e /o an CC lists to t%e mail object) mail)set/oAresses!toAresses"G mail)setCcAresses!ccAresses"G
mail)set-epl1/o!pa+an),alapatapuge)com"G
mail)setSenerDispla1>ame!Salesforce Support"G mail)setSubject!>e* 'ail is Create : "G mail)setame!attac%ment)pf"G efa)set
SFDC Integration:
99 Sen t%e email 1ou %a+e create) 'essaging)Sen.mail-esultJK mail-esult 'essaging)sen.mail!ne* 'essaging)Single.mail'essageJK mail H"G s1stem)ebug!%ere is t%e response RR Qmail-esult"G
&'( arsing: So often in SOA an -.S/ integrations *e come across &'( reaing9*riting) Salesforce %as pro+ie stanar class3 calle as3 DO' *%ic% is useful in parsing t%e &'( responses) 0ere is t%e sample e$ample to illustrate %o* to use met%os of DO' class5 met%os an properties in parsing &'( ata)
99 Sample coe to parse &'( response
public class DomDocument 99 ass in t%e -( for t%e reuest 99 For t%e purposes of t%is sample3assume t%at t%e -( 99 returns t%e &'( s%o*n abo+e in t%e response bo1 public +oi parse-esponseDom!String url" 0ttp % ne* 0ttp!"G 0ttp-euestre ne* 0ttp-euest!"G 99 url t%at returns t%e &'( in t%e response bo1 re)set.npoint!url"G re)set'et%o!./"G 0ttp-esponse res %)sen!re"G Dom)Document oc res)get
(et t%e sample &'( response be li,e belo*3
YaressRYnameRCapitalInfosolutionsY9nameR Ystreet?R'1t%ri+anamY9street?R Ystreet2RAmeerpetY9street2R Ycit1R01erabaY9cit1R YstateRAY9stateR Ycountr1RIniaY9countr1R Y9aressR
99-etrie+e t%e root element for t%is ocument) Dom)&'(>oe aress oc)get-oot.lement!"G String name aress)getC%il.lement!name3 null")get/e$t!"G String state aress)getC%il.lement!state3 null")get/e$t!"G 99 print out specific elements Capital Info Solutions # 86 86 86 42 86
SFDC Integration:
S1stem)ebug!>ame: Q name"G S1stem)ebug!State: Q state"G 99 Alternati+el13 loop t%roug% t%e c%il elements) 99 /%is prints out all t%e elements of t%e aress for!Dom)&'(>oe c%il : aress)getC%il.lements!"" S1stem)ebug!c%il)get/e$t!""G H H H
Y .n of t%e Document R
Capital Info Solutions3 01eraba)
Capital Info Solutions # 86 86 86 42 86