Slaesforce FAQ

how to write code that return an array in salesforce

by Christopher Windler Published 3 years ago Updated 2 years ago
image

global static String attachBlob (List<Attachment> getResult) { // your code return JSON.serialize (attachList); } I am not sure but I guess you may need to parse the javascript variable ie. result like this JSON.parse (result). this will give you the array

Full Answer

How do I return an array in Apex Salesforce?

0:213:53Create an Apex Class that Returns an Array or List of Strings - YouTubeYouTubeStart of suggested clipEnd of suggested clipSo now the class needs to have a public static methods called generate string alright and thisMoreSo now the class needs to have a public static methods called generate string alright and this method must return an array or a list of strings. And I must accept an income and integer as a parameter.

How do I return an array from a string in Apex?

The Apex class must have a public static method called 'generateStringArray'. The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array.

How do I use an array in Salesforce?

Let us understand the working of an Arrays in Apex by writing a simple program to display Array of strings in PageBlockTable. To create an Apex class in Salesforce, login to Salesforce -> Developer console -> File -> File -> New -> Apex class. Enter the Apex class name to create new Apex Class.

How do I return a string in Apex class?

Simple Apex class to return a list of stringsThe Apex class must be called 'StringArrayTest' and be in the public scope.The Apex class must have a public static method called 'generateStringArray'.The 'generateStringArray' method must return an array (or list) of strings.

Can we use array in Apex?

Arrays in Apex are basically the same as Lists in Apex. There is no logical distinction between the Arrays and Lists as their internal data structure and methods are also same but the array syntax is little traditional like Java.

How do I declare an array in Apex?

In Apex, there are two ways to declare an array. Syntax: DataType arrayname = new DataType[] {value 1, value 2}; For example, Integer[] marks =new Integer[] {1,2,3};

What is the difference between List and array in Salesforce?

Even though the size of the previous String array is defined as one element (the number between the brackets in new String), lists are elastic and can grow as needed provided that you use the List add method to add new elements. For example, you can add two or more elements to the colors list.

Can an array have variables?

An array is a variable containing multiple values. Any variable may be used as an array. There is no maximum limit to the size of an array, nor any requirement that member variables be indexed or assigned contiguously. Arrays are zero-based: the first element is indexed with the number 0.

How do I convert a String to a List in Salesforce?

Use the split method. this method will split the string using the provided regex. String str = '123, 456, 789'; List lstString = str.

How do I return multiple values from Apex?

Apex does not allow multiple return types. However, you can create a custom type to be returned from your method. It would have a Lead and a Set and a Set in it - allowing you to have strings and dates per Lead.

How do I convert a String to an integer in Salesforce?

Integer Methodsformat() Returns the integer as a string using the locale of the context user.valueOf(stringToInteger) Returns an Integer that contains the value of the specified String. ... valueOf(fieldValue) Converts the specified object to an Integer.

How do you write a method in Apex?

To define a method, specify the following:Optional: Modifiers, such as public or protected .Required: The data type of the value returned by the method, such as String or Integer. ... Required: A list of input parameters for the method, separated by commas, each preceded by its data type, and enclosed in parentheses () .More items...

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9