Apex List In SalesForce - C# Corner

文章推薦指數: 80 %
投票人數:10人

About SalesForce · public class ApexList { · public static void Listtest() { · List < String > Dept = new List < String > { · 'CSE', · 'EEE', · 'ECE' ... ApexListInSalesForce VijayaragavanS UpdateddateSep11,2019 29.3k 0 2 Readingthisarticle,youcanlearnandtesttheApexListandMethodsinSalesForce. facebook twitter linkedIn Reddit WhatsApp Email Bookmark Print OtherArtcile Expand AboutSalesForce   SalesForceisacloud-basedonlinesolutionforcustomerrelationshipmanagementorCRM.SalesForceprovidesallofourdepartmentslikemarketing,sales,commerce,andservicewithasharedviewofourcustomerswithasingleintegratedCRMplatform.   Apexisastronglytyped,object-orientedprogramminglanguagethatallowsdeveloperstoexecuteflowandtransactioncontrolstatementsonSalesForceserversinconjunctionwithcallstotheAPI.UsingsyntaxthatlookslikeJavaandactslikedatabasestoredprocedures,Apexenablesdeveloperstoaddbusinesslogictomostsystemevents,includingbuttonclicks,relatedrecordupdates,andVisualforcepages.ApexcodecanbeinitiatedbyWebservicerequestsandfromtriggersonobjects.–Salesforce  ApexCollectionsisatypeofvariable,itcanstoremultiplenumbersofrecords.ThedifferenttypesofCollectionsare,List,SetandMap.   Alistislikeanarray,asequentialcollectionofelementswithfirstindexpositionaszero.Listcancontainelementsofprimitivetypes,sObjects,user-definedobjects,Apexobjectsorevenothercollections.Alistcancontainuptofourlevelsofnestedcollections.Listcancontainduplicateelements   Readingthisarticle,youcanlearnandtesttheApexListandMethodsinSalesForce.   TheprerequisitesfortestingApexListsinSalesForceas,   RegisteraSalesforceFreeTrialaccountusingthefollowinglink.   Step1   LogintoyourSalesForceaccountandclicktheDeveloperConsole.     Step2   Now,wecancreateanewApexClassApexListfilenamedasApexList.apxc,       AftercreatingApexclassApexList,addaListtestmethodforcreatingandtestingtheListanditsmethods.     TheGeneralSyntaxforApexListis, List variablename = new List();   ApexDataTypepleasereferthelink.   TheDeptListcreationCodeis, List Dept = new List{'CSE','EEE','ECE'};   system.debug('Default Department List : '+Dept);   Step3   Next,wecanaddtheApexList importantpredefinedmethodslikeadd(ListElement),add(index,ListElement),addAll(fromList),size(),clear(),get(index),isEmpty(),andclone().   Thefirstmethodisadd(ListElement)–usingthismethod,wecaninsertanelementintothelist.Thecodeis, Dept.add('MECH');   Dept.add('IT');   system.debug('Using add(ListElement) - Department List : '+Dept);   NextMethodis,add(index,ListElement)-usingthismethod,wecaninserttheelementatthegivenindexnumber.Thecodeis, Dept.add(0,'Civil');   Dept.add(5,'Bio Technology');   system.debug('Using add(index, ListElement)-Department List : '+Dept);   NextMethodis,addAll(fromList)-usingthismethod,wecanaddalltheelementsinthelistspecified,andbothlistsshouldbeofthesametype. List Depttest=new List();   Depttest.addAll(Dept);   system.debug('Using addAll(fromList) - Department List : '+Depttest);   NextMethodis,size()-usingthismethod,wecangetthetotalnumberofelementsinthelist. Integer s=Dept.size();   system.debug('Using size() - Department Size : '+s);   NextMethodisget(index)-usingthismethod,itreturnstheelementwhichisatgivenindex. string str=Dept.get(3);   system.debug('Using get(index) - Department Index 3 is: '+str);   NextMethodisisEmpty()-usingthismethod,Itreturnstrueifthelistisempty. Boolean b=Dept.isEmpty();   system.debug('Using isEmpty() - Department Empty : '+b);   NextMethodisclone()-usingthismethod,wecancreateanothercopyofthelist. List Depttest2=new List();   Depttest2=Dept.clone();   system.debug('Using clone() - Department List 2 : '+Depttest2);   LastMethodisclear()–Thiswillremovealltheelementsfromthelist.Hencethelengthofthatlistwillbezero. Depttest2.clear();   system.debug('Using clear() - Department List 2 : '+Depttest2);   Finally,theApexList.apxcclasscodeis, public class ApexList {       public static void Listtest() {           List  Dept = new List  {               'CSE',               'EEE',               'ECE'           };           system.debug('Default Department List : ' + Dept);           //add(ListElement)           Dept.add('MECH');           Dept.add('IT');           system.debug('Using add(ListElement) - Department List : ' + Dept);           //add(index, ListElement)           Dept.add(0, 'Civil');           Dept.add(5, 'Bio Technology');           system.debug('Using add(index, ListElement)-Department List : ' + Dept);           //addAll(fromList)           List  Depttest = new List  ();           Depttest.addAll(Dept);           system.debug('Using addAll(fromList) - Department List : ' + Depttest);           //size()           Integer s = Dept.size();           system.debug('Using size() - Department Size : ' + s);           //get(index)           string str = Dept.get(3);           system.debug('Using get(index) - Department Index 3 is: ' + str);           //isEmpty()           Boolean b = Dept.isEmpty();           system.debug('Using isEmpty() - Department Empty : ' + b);           //clone()           List  Depttest2 = new List  ();           Depttest2 = Dept.clone();           system.debug('Using clone() - Department List 2 : ' + Depttest2);           //Clear()           Depttest2.clear();           system.debug('Using clear() - Department List 2 : ' + Depttest2);       }   }   Step4   ForDebuggingtheApexclassApexList,clicktheDebugmenuandselectOpenExecuteAnonymousWindow.     Now,writetheApexcodeforcallingListtest()methodandenabletheOpenlogoptionforviewingoutputandclickExecute.   ApexList.Listtest();   Step4   Now,wecanverifytheoutput.Afterclicking"Execute",thelogwillbeopenautomaticallyandselecttheDebugOnlyoption.     Summary   Now,youhavesuccessfullytestedtheApexListanditsmethodsinSalesForceenvironment. ApexListSalesForce. NextRecommendedReading FEATUREDARTICLES ViewAll TRENDINGUP 01DesignTheFullLoadAndDeltaLoadPatternsInSSIS02HandlingDataLoadTypesInStagingDatabase03WhatIsCleanArchitecture04HowToImplementCachingInThe.NETCoreWebAPIApplication05HowToPostDataInASP.NETUsingAJAXWithoutJSONFormSerializer06HowToCreateAndDestroyDynamicComponentsInAngular07WhatIsNewIn.NET6.008JWTAuthenticationWithRefreshTokensIn.NET6.009UsingAPIKeyAuthenticationToSecureASP.NETCoreWebAPI10UploadSingleOrMultipleFilesInASP.NETCoreUsingIFormFile ViewAll



請為這篇文章評分?