The Welkin Suite Forum

Snippet collection



Snippet collection

  • Please log in to reply

#1

ron.planken

    Posted 23 Jul 2015

    With the introduction of the Snipper manager I thought it would be a good idea to make a forum thread where we can exchange snippets we made. Snippets are located in the following location:


    (If you followed the default install path, otherwise change as needed)

    C:\Program Files (x86)\The Welkin Suite\The Welkin Suite\Extensions\Application\Editor\CodeSnippets\Snippets


    Simply copy a snippet and change the contents of the file for it to work. If you download a snippet you can drag and drop it in the directory for it to be picked up by the Welkin Suite.


    Follow the excellent post from the Welkin Suite team to find out more:

    http://welkinsuite.com/using-editing-and-modifying-apex-code-snippets/


    foreach.snippet

    This snippet contains a foreach loop. Although the loop in Apex is called for, it behaves as a foreach loop as in c#. It generates a piece of code as followed:

    for (sObject obj : objs)
    {
    
    
    }

    Unfortunately we are not allowed to upload snippet or zipfiles. So copy the following code and paste it into a .snippet file.

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    	<CodeSnippet Format="1.0.0">
    		<Header>
    			<Title>foreach</Title>
    			<Shortcut>method</Shortcut>
    			<Description>Code snippet for 'foreach' loop</Description>
    			<Author>Ron Planken</Author>
    			<SnippetTypes>
    				<SnippetType>Expansion</SnippetType>
    				<SnippetType>SurroundsWith</SnippetType>
    			</SnippetTypes>
    		</Header>
    		<Snippet>
    			<Declarations>
    				<Literal>
    					<ID>objtype</ID>
    					<Default>sObject</Default>
    					<ToolTip>The type of the objects being iterated over</ToolTip>
    				</Literal>
    				<Literal>
    					<ID>obj</ID>
    					<Default>obj</Default>
    					<ToolTip>Name of the variable that will contain the single item from the list</ToolTip>
    				</Literal>
    				<Literal>
    					<ID>list</ID>
    					<Default>objs</Default>
    					<ToolTip>Name of the variable that contains the list of objects to iterate over</ToolTip>
    				</Literal>
    			</Declarations>
    			<Code Language="Apex"><![CDATA[for ($objtype$ $obj$ : $list$)
    			{
    			$selected$ $end$
    			}]]>
    			</Code>
    		</Snippet>
    	</CodeSnippet>
    </CodeSnippets>
    


    1 replies to this topic

    #2

    vlgubanovich

      Posted 03 Aug 2015

      Hi Ron!


      Thanks for sharing this :)


      This topic looks like a good idea for collecting useful snippets from our community - I'll add link to this post to the blog post if you don't mind.


      Thanks,

      Vladimir


      Vladimir Gubanovich
      Head of Product
       
      The Welkin Suite
      skype id: vladimir.gubanovich
      e-mail: vladimir.gubanovich@welkinsuite.com





      Boost Your Productivity. Get Started Today

      Try Free Trial