Piotr Gajek

Type Casting in Apex

Hello devs,

What are Upcasting and Downcasting? How can you cast Apex Map, List, and Set? What is a supertype, and what is the difference between SObject and Object? Answers to these questions and much more can be found in this post!

Let's begin.

Before We Start

I am using different emojis to grab your attention:

  • 🚨 - Unexpected casting behavior.
  • ✅ - Code that works.
  • ❌ - Code that does not work.

What supertype is?

A supertype is an abstract/virtual class or an interface that is used by a child class.

The Parent interface is a supertype for the Child class.

A class can implements many interfaces, meaning that a class can have many supertypes .

The Parent abstract class is a supertype/superclass for the Child class.

A class can extends only one abstract class, but it can still implements many interfaces.

The Parent virtual class is a supertype/superclass for the Child class.

A class can extends only one virtual class, but it can still implements many interfaces.

Upcasting vs Downcasting

You know what supertype is, it's necessary to understand the difference between Upcasting and Downcasting .

Upcasting and Downcasting in Apex

To better understand upcasting and downcasting, we need some examples.

We have two classes (it can be also class and interface), Parent and Child .

  • Parent is a virtual class and has a virtual method.
  • Child extends the Parent class and override the virtual method.

If you don't understand what virtual means, you can refer to the Abstract, Virtual, Interface in Apex post.

  • Child extends the Parent class. It means that Parent is a supertype/superclass for Child . Because of this, the following syntax: Parent parent = new Child(); is valid.
  • Casting a subclass ( Child ) to a supertype/superclass ( Parent ) is called Upcasting .
  • Upcasting can be either explicit or implicit.

Implicit Upcasting

Upcasting can be done implicitly.

Explicit Upcasting

Code should be as simple as possible (KISS rule), so the better approach is to use implicit upcasting.

The parent variable has access to:

  • Parent public variables.
  • Parent public methods.
  • Child ONLY overriden methods.

Downcasting

  • Casting a supertype/superclass ( Parent ) to a subclass ( Child ) is called Downcasting .
  • Upcasting can be done ONLY explicitly.

Implicit Downcasting

Downcasting CANNOT be implicit. Why?

  • There can be many children of the Parent class. e.g public class Child2 extends Parent { ... } .
  • Apex needs to know to what type the variable should be cast to.

Explicit Downcasting

You have to cast explicitly (Child) so the compiler checks in the background if this type of casting is possible or not. If not, you will get System.TypeException: Invalid conversion from runtime type Parent to Child .

The child variable has access to:

  • Child ALL public methods and variables.
  • SObject Class

SObject is a supertype for:

  • all standard objects (Account, Contact, etc.)
  • all custom objects (MyCustomObject__c)

Object is a supertype for:

  • all standard objects
  • all custom objects
  • all apex classes
  • all collections (List, Set and Map)
  • all apex types (Integer, String, Boolean)
  • Methods inherited from Object class

SObject and Object

Sobject and object - instanceof.

  • SObject is an instance of Object . Object is a supertype for SObject .

SObject and Object - casting

Object to sobject.

  • Object needs to be explicitly cast to SObject .
  • Object is a supertype of SObject .
  • Conversion from Object to SObject is called Downcasting .
  • As you already know from Downcasting section. Downcasting needs to be explicit (SObject) .

SObject to Object

  • SObject can be explicitly or implicitly cast to Object .
  • Conversion from SObject to Object is called Upcasting .
  • As you already know from Upcasting section. Upcasting can be done explicitly or implicitly.

Inherited methods

  • Interestingly, Object is a supertype for SObject , but SObject does NOT inherit Object methods like toString(), equals(), hashCode(), clone() . SObject has all of the following methods SObject class methods. .

However, all Apex Classes inherit Object methods ( toString() , equals() , hashCode() , clone() ).

Standard/Custom Object

Standard/custom object - instanceof.

  • Standard/Custom Object is an instance of SObject and Object .
  • SObject and Object are supertypes for Standard/Custom Objects .

Standard/Custom Object to SObject - casting

Standard/custom object to sobject.

Why it works?

  • SObject is a supertype for Account , Contact , and other standard or custom objects.
  • Conversion from Standard/Custom Object to SObject is called Upcasting .

SObject to Standard/Custom Object

  • Conversion SObject to Standard/Custom Object is called Downcasting .
  • As you already know from Downcasting section. Downcasting can be done ONLY explicitly.

Standard/Custom Object to Object - casting

Standard/custom object to object.

  • Object is a supertype for Account , Contact , and other standard or custom objects.
  • Conversion from Standard/Custom Object to Object is called Upcasting .

Object to Standard/Custom Object

  • Conversion Object to Standard/Custom Object is called Downcasting .

Primitive Types

Primitive types - instanceof.

  • All Primitive Data Types are instanceOf Object class.
  • Object is a supertype for all primitve types.

Primitive Types - casting

  • Primitive Types can be implicilty cast to Object .
  • Object is a supertype of all Primitive Types.
  • Conversion from Primitive Type to Object is called Upcasting .

List<SObject>

List<sobject> - instanceof.

  • List<SObject> is an instance of concrete Standard/Custom Object!
  • List<SObject> is NOT an instance of List<Object> .

List<SObject> - casting

List<sobject> to list<object>.

  • List<SObject> is NOT an instance of List<Object> (based on instanceOf ), but you can still assign List<SObject> to List<Object> . Do not trust instanceOf !

List<Standard/Custom> to List<SObject>

  • List<SObject> is a supertype for List<Standard/Custom> .
  • Conversion from Standard/Custom Object to List<SObject> is called Upcasting .

List<SObject> to List<Standard/Custom>

Upcasting/Downcasting (?)

  • List<Standard/CustomObject> is an instance of List<SObject> , and List<SObject> is an instance of List<Standard/CustomObject> .
  • List<Standard/CustomObject> is a supertype for List<SObject> , and List<SObject> is a supertype for List<Standard/CustomObject> .
  • You can do implicit casting.

List<Object>

List<object> - instanceof.

  • SObject is always an instance of Object , hovever List<SObject> is NOT an instance of List<Object> .

List<Object> - casting

  • We can cast List<ConcreteType> to List<Object> ,
  • List<Object> is a supertype of List<ConcreteType> .
  • Conversion from List<ConcreteType> to List<Object> is called Upcasting .
  • There is no need to cast explicitly by adding (List<Object>) .
  • List<SObject> is NOT an instance of List<Object> (based on instanceOf ), but you can still assign List<SObject> to List<Object> .

List Summary

List casting in Apex is a bit unusual.

What is common:

  • List<ConcreteType> is an instance of List<Object> .
  • List<Object> is a supertype for List<ConcreteType> .

What is unexpected:

  • Based on instanceOf . List<SObject> is not an instance of List<Object> , but you can still assign List<SObject> to List<Object> .
  • You can even assign List<SObject> to List<Object> . Do not trust instanceOf !
  • Even more unexpectedly, List<SObject> is an instance of concrete List<Standard/Custom> Object!

Set<SObject>

Set<sobject> - instanceof.

  • Set<Standard/CustomObject> is NOT an instance of Set<SObject> .

Set<SObject> - casting

Set<sobject> to set<object>.

  • You CANNOT cast Set<SObject> to Set<Object>

Set<Standard/Custom> to Set<SObject>

  • You CANNOT cast Set<Standard/Custom> to Set<SObject>

Set<SObject> to Set<Standard/Custom>

  • You CANNOT cast Set<SObject> to Set<Standard/Custom>

Set<Object>

Set<object> - instanceof.

  • Other than List , Set<Object> is NOT a supertype for Set<ConcreteType> .

Set<Object> - casting

  • We CANNOT cast Set<ConcreteType> to Set<Object> ,

Even if you explicitly add casting (Set<Object>) it will not work.

Set Summary

Map<sobject>, map<sobject> - instanceof.

I skipped cases where SObject is a key. SObject should never be a key in the Map.

  • Map<Object, Account> is an instance of Map<Object, Object> , which means that Map<Object, Object> is a supertype of Map<Object, Account> .
  • Map<Object, Account> is an instance of Map<Object, SObject> , which means that Map<Object, SObject> is a supertype of Map<Object, Account> .

Map<SObject> - casting

  • Map<Object, Object> is a supertype for Map<Object, Standard/CustomObject> .
  • Conversion from Map<Object, Standard/CustomObject> to Map<Object, Object> is called Upcasting .

Even explicit casting will not work. The error is different.

How to fix Map downasting?

Map<Object>

Map<object> - instanceof.

Maps are the same instance only in the following cases:

  • new Map<MyType, MyType>() instanceOf new Map<MyType, Object>
  • new Map<Object, MyType>() instanceOf new Map<Object, Object>

Key Type must be the same.

Map<Object> - casting

You can cast implicitly only when:

Map Summary

Starting from Summer 23', Set implements Iterable interface as List does.

Iterable List

Iterable list - instanceof.

Not surprisingly, a List of concrete types is also an instance of Iterable<Object> .

  • Instance of List<Object> and Set<Object> are always an instance of System.Iterable<Object> .

Iterable List - casting

It's really interesting.

e.g List<String> is an instance of Iterable<Object> , but you CANNOT use Iterable<Object> as a supertype .

You need to assign List<String> to List<Object> and after it to Iterable<Object> .

Iterable Set

Iterable set - instanceof.

  • An interesting thing is that you're getting an error Operation instanceOf is always true... .
  • Set<ConcreteType> is also an instance of Iterable<Object> , but not Set<SObject> .

Iterable Set - casting

  • You CAN use Iterable<Object> as a supertype for Set , which you CANNOT do with a List .
  • You CANNOT assign Set<SObject> to Iterable<Object> .

It's quite a big deal. Let's check an example:

How to fix it?

  • You need two methods ( isIn(Iterable<Object> inList) and isIn(List<Object> inList) ) in the interface that will be covered by one method ( isIn(Iterable<Object> inList) in concrete class!

Iterable Summary

  • You CANNOT use Iterable<Object> as a supertype for List<ConcreteType> . You need to assign List<ConcreteType> to List<Object> and after it to Iterable<Object> .
  • Set<ConcreteType> is instance of Iterable<Object> .
  • Set<Sobject> is NOT instance of Set<SObject> .

Casting Rules

Cast to everything.

The problem with the solution below is performance.

Casting Cheat Sheet

Do not trust instanceof.

Based on the type system is broken with regards to collections :

Pretty much the entire "Type" system that governs Maps, Sets, and Lists is broken. Do not trust instanceOf, use your own logical assessment to determine if something is safe or not.

As shown in the post, there are cases where instanceOf does not work correctly.

List<SObject> and List<Object>

instanceOf says that " List<SObject> is never an instance of List<Object> ", but you can assign List<SObject> to List<Object> .

List<ConcreteType> and Iterable<Object>

instanceOf says that List<ConcreteType> is an instance of Iterable<Object> , but you CANOT assign List<ConcreteType> to Iterable<Object> .

SObject Casting

  • Casting from Standard/Custom Object to SObject is called upcasting and can be implicitly.
  • Casting from SObject to Standard/Custom Object is called downcasting and it needs to be explicit.
  • SObject is instance of Object . Object is a supertype for SObject .
  • Casting from SObject to Object is called upcasting and can be implicit.
  • Casting from Object to SObject is called downcasting and it needs to be explicit.

Object Casting

Primitive types casting.

  • All Primitive Data Types are instanceOf Object . Object is a supertype for all primitve types.
  • Casting from Primitive Data Types to Object is called upcasting and can be implicit.

List Casting

  • All List<ConcreteType> are instance of List<Object> . List<Object> is a supertype of List<ConcreteType> .
  • Based on instanceOf method List<SObject> is NOT an instance of List<Object> , but still you can assign List<SObject> to List<Object> . Do not trust instanceOf .
  • Casting from List<ConcreteType> to List<Object> is called upcasting and can be implicit.
  • List<Standard/Custom> is a supertype for List<SObject> .

Set Casting

  • You CANNOT cast Set<ConcreteType> to Set<Object> .

Map Casting

  • Map<Object, Account> is instance of Map<Object, Object> , it means that Map<Object, Object> is a supertype for Map<Object, Account> .
  • Map<Object, Account> is instance of Map<Object, SObject> , it means that Map<Object, SObject> is a supertype for Map<Object, Account> .
  • To fix System.TypeException: Invalid conversion from runtime type Map<ANY,SObject> to Map<ANY,Account> dynamic Map initiation is needed.

Iterable Casting

  • Set<ConcreteType> is instance of Iterable<Object> , but Set<SObject> is NOT instance of Iterable<SObject> .
  • Unexpected Iterable behavior in Apex
  • Classes and Casting
  • Using the instanceOf Keyword
  • Upcasting Vs Downcasting in Java

Buy Me A Coffee

You might also like

logo

Salesforce OAuth 2.0 Flows: Integrate in the right way

TL;DR I just want to know which flow to use If you’re short on time or just want to know what flow is for you, just go here. Introduction Brief Overview OAuth, which stands for Open Authorization, is an open-standard protocol that provides users with secure access to resources on an application, such as Salesforce, […]

logo

Advanced Salesforce LWC debugging with Chrome Developer Tools

LWC debugging and development with Chrome Developer Tools – learn how Salesforce LWC developer can debug and develop Lightning Web Components effectively without console.logs.

Developer 1 - Apex Language Basics

12 - primitive data types.

  • Apex uses the same primitive data types as SOAP API, except for higher-precision Decimal type in certain cases.
  • All primitive data types are passed by value.
  • All Apex variables (both class member variables and method variables) are initialized to null. Initiatlize variabbles to appropriate values before using them. For example, initialize Boolean variables to false.
  • Primitive Data Type developer doc
  • Range from simple String s to complex DateTime s
  • Apex does some datatype checking, so you cannot assign the string 'true' (instead of true ) to a Boolean variable as it generates an “Illegal Assignment” error.
  • There are many interesting “helper methods” available by typing the datatype and . , so String. , for example.
  • Blob - commonly used for Salesforce files
  • Object - generic Apex datatype, all primitives and more complex types are of type Object
  • Long - lets you have a higher-precision Integer

13 - Complex Data Types

  • Created by new Account();
  • If inside a method, do not need to include the access modifier ( public ), this is only needed at the top level class
  • Parameters that are passed in ( new Account(name = testString + '1') ) are sent to the “constructor”
  • + is concatenation, if used with strings
  • Executing the trigger and handler above by inserting an account produces the following debug notes

illegal assignment from list to string apex

14 - Arrays

  • An Array is just a term for a collection of multiple variables
  • Arrays: List, Set, Map
  • When instantiating, use {}
  • Indexes are zero-based (0-4, below)
  • Overall size of the list is the count of items (5, below)
  • To remove an item from a list, need to remove by index
  • If a set already includes a value, adding the same value again will not change the set
  • An advantage of sets over lists is that sets can test whether the set contains a value
  • To remove an item from a set, need to remove the value itself
  • Collection of correspondences between values
  • keys must be unique. Mapping a value already in the map to a new value will overwrite the existing value.
  • Useful paradigm is a map of Id and sObject s. Anytime we have an Id we can run the get method, passing in the Id, and then get out the Account record that matches the Id.

15 - If Else

  • Recall the one-trigger per object best practice - this is because if the triggers are separate there is no way to check which trigger runs first if you are running multiple triggers on the same object.

16 - Comparison Operators

  • == - comparison operator
  • = - assignment operator
  • != - not equal
  • && , || - and, or

17 - Ternary Operators

  • Ternary operators combine an if statement and an assignment into a single line
  • some_value = if_condition ? assignment_if_true : assignment_if_false

Without ternary operator

With ternary operator

18 - Switch Statements

  • Switch statements are way of simplify code from a standard set of if-statements
  • Note: can only run switch statements on String s, Integer s, and sObject s

19 - For Loops

Standard For Loop

  • for loop continues until continuation_condition evaluates to false

For Each Loop

  • “For Each” loops are similar, just more brief. They are used to loop through a list of items.

20 - While Loops

  • While loop may not execute at all
  • Do While loop is similar - always executes at least once

21 - try/catch

  • List index is out of bounds

illegal assignment from list to string apex

  • .getMessage() returns a string, so all string methods work on it
  • throw ex; throws the exception
  • insert errorRecord could be used to create an error record log in the database that could be reviewed later

illegal assignment from list to string apex

22 - Custom Exceptions

  • Create by creating a new Apex class. If the name of the class includes “Exception” then the boilerplate class code will include extends Exception .

illegal assignment from list to string apex

23 - Challenge 1 - Basic Trigger Setup

  • Tax_Percentage__c (percentage field)
  • Tax__c (Currency field)
  • Total_Price__c (Currency field)
  • Also includes the Challenge 1 opportunity page layout
  • Calculate tax any time an Opportunity is inserted or updated
  • Need to convert Tax_Percentrage__c to a decimal value to multiply by Amount
  • Total_Price__c : Tax__c + Amount
  • We don’t want to run the calculations if Amount or Tax_Percentage__c are not populated (to avoid errors)
  • We don’t want to run the calculations on update if neither Amount nor Tax_Percentage__c are changed in the update
  • Keep triggers logic-less and call logic in a handler
  • Ensure class access is set up correctly. Methods only called from the same class should be kept private. Others should be public or global.
  • Trigger.new : List of records
  • Trigger.newMap , Trigger.oldMap : same records, but as a Map : Map<Id, Opportunity>
  • Be aware that in an insert trigger, you cannot reference Trigger.old or Trigger.oldMap , so be sure to only reference old records from the update context.
  • My First Solution:

illegal assignment from list to string apex

24 - Challenge 1 - Work Check

  • Comments as shown below are a best practice
  • global class definition so it is as accessible as possible
  • global method means anyone can call it
  • static method means it can be called directly from the handler
  • newMap.keySet() returns the IDs in the Map<Id, Opportunity>
  • newMap.get(oppId) returns the new record
  • Whenever there is a sequence of calculations like newRecord.Tax__c = (newRecord.Tax_Percentage__c/100) * newRecord.Amount; or newRecord.Total_Price__c = newRecord.Tax__c + newRecord.Amount; its a good idea to abstract the logic into its own method
  • Marketing Cloud

Experiences

Access Trailhead, your Trailblazer profile, community, learning, original series, events, support, and more.

Apex Reference Guide

Summer '24 (API version 61.0)

Search Tips:

  • Please consider misspellings
  • Try different search keywords

RestRequest Class

An Apex RESTful Web service method is defined using one of the REST annotations. For more information about Apex RESTful Web service, see  Exposing Apex Classes as REST Web Services .

Example: An Apex Class with REST Annotated Methods

Restrequest constructors, restrequest properties, restrequest methods.

The following are constructors for RestRequest .

  • RestRequest() Creates a new instance of the System.RestRequest class.

RestRequest()

public RestRequest()

The following are properties for RestRequest .

While the RestRequest List and Map properties are read-only, their contents are read-write. You can modify them by calling the collection methods directly or you can use of the associated RestRequest methods shown in the previous table.

  • headers Returns the headers that are received by the request.
  • httpMethod Returns one of the supported HTTP request methods.
  • params Returns the parameters that are received by the request.
  • remoteAddress Returns the IP address of the client making the request.
  • requestBody Returns or sets the body of the request.
  • requestURI Returns or sets everything after the host in the HTTP request string.
  • resourcePath Returns the REST resource path for the request.

public Map< String , String > headers {get; set;}

Property Value

Type: Map < String , String >

public String httpMethod {get; set;}

Type: String

Possible values returned:

public Map < String , String > params {get; set;}

remoteAddress

public String remoteAddress {get; set;}

requestBody

public Blob requestBody {get; set;}

If the Apex method has no parameters, then Apex REST copies the HTTP request body into the RestRequest.requestBody property. If there are parameters, then Apex REST attempts to deserialize the data into those parameters and the data won't be deserialized into the RestRequest.requestBody property.

public String requestURI {get; set;}

For example, if the request string is https://instance.salesforce.com/services/apexrest/Account/ then the requestURI is /Account/ .

resourcePath

public String resourcePath {get; set;}

For example, if the Apex REST class defines a urlMapping of /MyResource/* , the resourcePath property returns /services/apexrest/MyResource/* .

The following are methods for RestRequest . All are instance methods.

At runtime, you typically don't need to add a header or parameter to the RestRequest object because they are automatically deserialized into the corresponding properties. The following methods are intended for unit testing Apex REST classes. You can use them to add header or parameter values to the RestRequest object without having to recreate the REST method call.

  • addHeader(name, value) Adds a header to the request header map in an Apex test.
  • addParameter(name, value) Adds a parameter to the request params map in an Apex test.

addHeader(name, value)

public Void addHeader( String name, String value)

Return Value

This method is intended for unit testing of Apex REST classes.

  • set-cookie2
  • content-length
  • authorization

addParameter(name, value)

public Void addParameter( String name, String value)

illegal assignment from list to string apex

Class Help: Illegal assignment from Schema.SObjectField to String at line 3 column 1

  • Classificar por mais útil
  • Classificar por data

illegal assignment from list to string apex

You can call methods in apex classes from your trigger. I just did some refactoring on the code you provided. Please let me know if this helps you.

Public class Job_Description_Transfer {

public string cleanseOpportunityDescription(string oppDescription)

  String RegEx ='(</{0,1}[^>]+>)';

  return oppDescription.replaceAll(RegEx, '');

  • Lista com marcadores
  • Lista numerada
  • Adicionar link
  • Bloco de códigos
  • Inserir imagem
  • Anexar arquivos

IMAGES

  1. Salesforce: Format specific date in Apex as dd/mm/yyyy

    illegal assignment from list to string apex

  2. Salesforce: Illegal assignment from List<SObject> to List<String> (3 Solutions!!)

    illegal assignment from list to string apex

  3. apex

    illegal assignment from list to string apex

  4. Salesforce: Illegal assignment from List to String (2 Solutions

    illegal assignment from list to string apex

  5. Salesforce: Illegal assignment from Schema.SObjectField

    illegal assignment from list to string apex

  6. apex

    illegal assignment from list to string apex

VIDEO

  1. NIG SOLDIERS BEGGED B L A IN THE FOREST IN ORLU AS 65 OF THEM WERE CAPTURED FOR ILLEGAL ASSIGNMENT

  2. They understood the assignment. 😂🤣

  3. Apex

  4. When to use containskey method in Apex? 🔑

  5. How Are These Players Not Banned?

  6. String of illegal dumping incidents leads to closure of Avra Valley area

COMMENTS

  1. Apex Error: Illegal assignment from List<String> to String

    Now if you need to add the list of regions at once in Region__c, then you might need to JSON.serialize and then convert to string and add. Note: Make sure the length of the text field does not exceed the data.

  2. salesforce

    OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

  3. Salesforce: Illegal assignment from list to list ...

    Salesforce: Illegal assignment from list to list (OpportunityContactRole to String)Helpful? Please support me on Patreon: https://www.patreon.com/roelvandep...

  4. Salesforce: Illegal assignment from List<SObject> to List<String> (3

    Salesforce: Illegal assignment from List<SObject> to List<String>Helpful? Please support me on Patreon: https://www.patreon.com/roelvandepaarWith thanks & p...

  5. Blob Class

    Blob Methods. The following are methods for Blob. size () Returns the number of characters in the Blob. toPdf (stringToConvert) Creates a binary object out of the given string, encoding it as a PDF file. toString () Casts the Blob into a String. valueOf (stringToBlob)

  6. Exception Class and Built-In Exceptions

    An illegal argument was provided to a method call. For example, a method that requires a non-null argument throws this exception if a null value is passed into the method. InvalidHeaderException: An illegal header argument was provided to an Apex REST call.

  7. Type Casting in Apex

    All Primitive Data Types are instanceOf Object class.; Object is a supertype for all primitve types.; Primitive Types - casting. Upcasting. Primitive Types can be implicilty cast to Object.; Why? Object is a supertype of all Primitive Types.; Conversion from Primitive Type to Object is called Upcasting.; As you already know from Upcasting section. Upcasting can be done explicitly or implicitly.

  8. Developer 1

    13 - Complex Data Types. The line public Account testAccount = new Account(name = testString + '1'); just creates the account in Apex, it does not insert it into the database . Created by new Account();; If inside a method, do not need to include the access modifier (public), this is only needed at the top level classParameters that are passed in (new Account(name = testString + '1')) are sent ...

  9. RestRequest Class

    The following example shows you how to implement the Apex REST API in Apex. This class exposes three methods that each handle a different HTTP request: GET, DELETE, and POST. You can call these annotated methods from a client by issuing HTTP requests. account.Name = name; account.phone = phone;

  10. Class Help: Illegal assignment from

    2014年2月14日 5:57. You can call methods in apex classes from your trigger. I just did some refactoring on the code you provided. Please let me know if this helps you. Apex Controller. Public class Job_Description_Transfer {. public string cleanseOpportunityDescription (string oppDescription) {. String RegEx =' (</ {0,1} [^>]+>)';

  11. Class Help: Illegal assignment from

    Class Help: Illegal assignment from Schema.SObjectField to String at line 3 column 1 Opportunity.Description__c is a Long Rich text field. Global with sharing class Job_Description_Transfer {

  12. Create current date in String format and parse to date as string in Apex

    parse(stringDate) Constructs a Date from a String. The format of the String depends on the local date format. valueOf(stringDate) Returns a Date that contains the value of the specified String. What I wanted was the parse: String inputDate = date.today().format(); / Date dateFromInput = date.parse(inputDate);

  13. Illegal assignment from System.JSONParser to JsonParser

    You may have two approaches: If you have already map the JSON into an Apex class, you may just use. JSON2Apex aClass = (JSON2Apex) System.JSON.deserialize(resp, JSON2Apex.class); Where JSON2Apex is the mapping Apex class. Use the JSON.deserializeUntyped(String jsonString) to deserialize the JSON to any Object in Apex class, like: