{"id":538,"date":"2019-05-31T12:06:17","date_gmt":"2019-05-31T12:06:17","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=538"},"modified":"2019-06-03T11:35:32","modified_gmt":"2019-06-03T11:35:32","slug":"salesforce-apex-programming","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/","title":{"rendered":"Salesforce Apex Programming"},"content":{"rendered":"<p><strong>What is Apex?<\/strong><br \/>\nApex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java which is also an object-oriented programming language. Apex has built-in functions or procedures for operations like INSERT, UPDATE, DELETE and also DML Exception handling. It uses a direct reference to schema objects like sObject.<\/p>\n<p>Apex is part of the salesforce releases and updates in the Salesforce cloud platform automatically with every new Salesforce release.<\/p>\n<p><strong>Some of the important apex applications are:<\/strong><br \/>\n1.) Create web service and integrate with external systems.<br \/>\n2.) Email services.<br \/>\n3.) Create custom transactional logic.<br \/>\n4.) Perform complex validation over multiple objects at the same time and also custom validation implementation.<\/p>\n<p>Apex works with SOSL and SOQL query languages that are designed specifically to work in the Salesforce cloud platform.<\/p>\n<p><strong>Apex SOSL :<\/strong><br \/>\nSOSL refers to the Salesforce Object Search Language. It has the capability of searching a particular string across multiple objects. Some points on SOSL:<br \/>\n1.) Many objects can be searched at a time.<br \/>\n2.) It can be used in classes but not in the trigger.<br \/>\n3.) DML operations can not be performed on searched results.<br \/>\n4.) It can only query EMAIL, text and phone type of fields.<br \/>\n5.) It returns the fields and not the object.<\/p>\n<p><strong>Apex SOQL :<\/strong><br \/>\nSOQL refers to the Structured Object Query language. It is used to perform DML operations like INSERT, UPDATE, DELETE, UPSERT, etc. Some points on SOQL:<br \/>\n1.) Only one object can be searched at a time.<br \/>\n2.) It can be used in classes and triggers and can query all type of fields.<br \/>\n3.) DML operations can only be performed on query results.<br \/>\n4.) Returns records and not the fields.<\/p>\n<p><strong>Apex classes can be executed from so many ways in the salesforce:<\/strong><br \/>\n1.) Scheduling the apex class.<br \/>\n2.) Using triggers or process builder.<br \/>\n3.) Using web services.<br \/>\n4.) Using SOAP or REST API.<br \/>\n5.) Using an anonymous block.<br \/>\n6.) Asynchronous apex or invoking javascript in vf page.<\/p>\n<p><strong>Apex triggers:<\/strong><br \/>\nApex triggers are like stored procedures which execute when a particular event occurs. A trigger executes before and after an event occurs on record. Events on which triggers can be executed:<br \/>\n1. Insert<br \/>\n2. Update<br \/>\n3. Delete<br \/>\n4. Upsert<br \/>\n5. Undelete<br \/>\n6. merge<\/p>\n<p><strong>The syntax of apex programming language:<\/strong><\/p>\n<pre>\/\/ Define a class in salesforce\r\npublic class createAccount \r\n{\r\n\r\n  \/\/Define a function in apex\r\n  public void create() \r\n  {\r\n    Account account = new Account();\r\n    account.Name = \u2018test\u2019;\r\n\r\n    \/\/ Save the data in account object using Database.insert function\r\n    Database.SaveResult accountResult = Database.insert(account, false);\r\n\r\n    \/\/ Iterate through each returned result\r\n    if (accountResult.isSuccess()) \r\n    {\r\n      \/\/ Operation was successful, so get the ID of the record that was processed\r\n      System.debug('Successfully created account. ID: ' + accountResult.getId());\r\n    } else \r\n    {\r\n      \/\/ Operation failed, so get all errors                \r\n      for (Database.Error err: accountResult.getErrors()) \r\n      {\r\n        System.debug('The following error has occurred.');\r\n        System.debug(err.getStatusCode() + ': ' + err.getMessage());\r\n        System.debug('Account fields that affected this error: ' + err.getFields());\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is Apex? Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is<\/p>\n","protected":false},"author":1,"featured_media":544,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[42,7,19,18,41,43],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog - Salesforce Apex Programming<\/title>\n<meta name=\"description\" content=\"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog - Salesforce Apex Programming\" \/>\n<meta property=\"og:description\" content=\"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-31T12:06:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-03T11:35:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/05\/Salesforce-Apex-blog.png\" \/>\n\t<meta property=\"og:image:width\" content=\"298\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Salesforce Apex Programming\",\"datePublished\":\"2019-05-31T12:06:17+00:00\",\"dateModified\":\"2019-06-03T11:35:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\"},\"wordCount\":359,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"apex\",\"Online certification\",\"online learning\",\"programming certification\",\"salesforce\",\"triggers\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\",\"url\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\",\"name\":\"StudySection Blog - Salesforce Apex Programming\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2019-05-31T12:06:17+00:00\",\"dateModified\":\"2019-06-03T11:35:32+00:00\",\"description\":\"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Salesforce Apex Programming\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog - Salesforce Apex Programming","description":"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog - Salesforce Apex Programming","og_description":"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.","og_url":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2019-05-31T12:06:17+00:00","article_modified_time":"2019-06-03T11:35:32+00:00","og_image":[{"width":298,"height":204,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/05\/Salesforce-Apex-blog.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Salesforce Apex Programming","datePublished":"2019-05-31T12:06:17+00:00","dateModified":"2019-06-03T11:35:32+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/"},"wordCount":359,"commentCount":1,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["apex","Online certification","online learning","programming certification","salesforce","triggers"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/","url":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/","name":"StudySection Blog - Salesforce Apex Programming","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2019-05-31T12:06:17+00:00","dateModified":"2019-06-03T11:35:32+00:00","description":"Apex is an object-oriented programming language designed for Salesforce cloud platform. The syntax of the apex is like java.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/salesforce-apex-programming\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/salesforce-apex-programming\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Salesforce Apex Programming"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":1152,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/538"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":10,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":553,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/538\/revisions\/553"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/544"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}