No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
sObject Class
Namespace
Usage
sObject methods are all instance methods, that is, they are called by and operate on a particular instance of an sObject, such as an account or contact. The following are the instance methods for sObjects.
For more information on sObjects, see sObject Types.
SObject Methods
The following are methods for SObject. All are instance methods.
addError(String)
Signature
public Void addError(String errorMsg)
Parameters
- errorMsg
- Type: String
The error message to mark the record with.
Return Value
Type: Void
Usage
When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error message is displayed in the application interface.
See Triggers and Trigger Exceptions.
When used in Visualforce controllers, the generated message is added to the collection of errors for the page. For more information, see Validation Rules and Standard Controllers in the Visualforce Developer's Guide.
addError(String, Boolean)
Signature
public Void addError(String errorMsg, Boolean escape)
Parameters
Return Value
Type: Void
Usage
The escaped characters are: \n, <, >, &, ", \, \u2028, \u2029, and \u00a9. This results in the HTML markup not being rendered; instead it is displayed as text in the Salesforce user interface.
addError(Exception)
Signature
public Void addError(Exception exceptionError)
Parameters
- exceptionError
- Type: System.Exception
An Exception object or a custom exception object that contains the error message to mark the record with.
Return Value
Type: Void
Usage
When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error message is displayed in the application interface.
See Triggers and Trigger Exceptions.
When used in Visualforce controllers, the generated message is added to the collection of errors for the page. For more information, see Validation Rules and Standard Controllers in the Visualforce Developer's Guide.
addError(Exception, Boolean)
Signature
public Void addError(Exception exceptionError, Boolean escape)
Parameters
- exceptionError
- Type: System.Exception
An Exception object or a custom exception object that contains the error message to mark the record with.
- escape
- Type: Boolean
Indicates whether any HTML markup in the custom error message should be escaped (true) or not (false).
Return Value
Type: Void
Usage
field.addError(String)
Signature
public Void addError(String errorMsg)
Parameters
- errorMsg
- Type: String
Return Value
Type: Void
Usage
- When used on Trigger.new in before insert and before update triggers, and on Trigger.old in before delete triggers, the error appears in the application interface.
- When used in Visualforce controllers, if there is an inputField component bound to field, the message is attached to the component. For more information, see Validation Rules and Standard Controllers in the Visualforce Developer's Guide.
- This method is highly specialized because the field identifier is not actually the invoking object—the sObject record is the invoker. The field is simply used to identify the field that should be used to display the error.
- This method will likely change in future versions of Apex.
See Triggers and Trigger Exceptions.
Example
1Trigger.new[0].myField__C.addError('bad');field.addError(String, Boolean)
Signature
public Void addError(String errorMsg, Boolean escape)
Parameters
Return Value
Type:
Usage
clone(Boolean, Boolean, Boolean, Boolean)
Signature
public sObject clone(Boolean opt_preserve_id, Boolean opt_IsDeepClone, Boolean opt_preserve_readonly_timestamps, Boolean opt_preserve_autonumber)
Parameters
- opt_preserve_id
- Type: Boolean
- (Optional) Determines whether the ID of the original object is preserved or cleared in the duplicate. If set to true, the ID is copied to the duplicate. The default is false, that is, the ID is cleared.
- opt_IsDeepClone
- Type: Boolean
- (Optional) Determines whether the method creates a full copy of
the sObject field, or just a reference:
- If set to true, the method creates a full copy of the sObject. All fields on the sObject are duplicated in memory, including relationship fields. Consequently, if you make changes to a field on the cloned sObject, the original sObject is not affected.
- If set to false, the method performs a shallow copy of the sObject fields. All copied relationship fields reference the original sObjects. Consequently, if you make changes to a relationship field on the cloned sObject, the corresponding field on the original sObject is also affected, and vice-versa. The default is false.
- opt_preserve_readonly_timestamps
- Type: Boolean
- (Optional) Determines whether the read-only timestamp fields are preserved or cleared in the duplicate. If set to true, the read-only fields CreatedById, CreatedDate, LastModifiedById, and LastModifiedDate are copied to the duplicate. The default is false, that is, the values are cleared.
- opt_preserve_autonumber
- Type: Boolean
- (Optional) Determines whether auto number fields of the original object are preserved or cleared in the duplicate. If set to true, auto number fields are copied to the cloned object. The default is false, that is, auto number fields are cleared.
Return Value
Type: sObject (of same type)
Usage
get(String)
Signature
public Object get(String fieldName)
Parameters
- fieldName
- Type: String
Return Value
Type: Object
Usage
For more information, see Dynamic SOQL.
get(Schema.sObjectField)
Signature
public Object get(Schema.sObjectField field)
Parameters
- field
- Type: Schema.SObjectField
Return Value
Type: Object
Usage
For more information, see Dynamic SOQL.
getOptions()
Signature
public Database.DMLOptions getOptions()
Return Value
Type: Database.DMLOptions
getSObject(Schema.SObjectField)
Signature
public sObject getSObject(Schema.SObjectField fieldName)
Parameters
- fieldName
- Type: Schema.SObjectField
Return Value
Type: sObject
getSObjects(String)
Signature
public sObject[] getSObjects(String fieldName)
Parameters
- fieldName
- Type: String
Return Value
Type: sObject[]
Usage
For more information, see Dynamic DML.
getSObjects(Schema.SObjectType)
Signature
public sObject[] getSObjects(Schema.SObjectType fieldName)
Parameters
- fieldName
- Type: Schema.SObjectType
Return Value
Type: sObject[]
getSObjectType()
Signature
public Schema.SObjectType getSObjectType()
Return Value
Type: Schema.SObjectType
Usage
For more information, see Understanding Apex Describe Information.
put(String, Object)
Signature
public Object put(String fieldName, Object value)
Parameters
- fieldName
- Type: String
- value
- Type: Object
Return Value
Type: Object
put(Schema.SObjectField, Object)
Signature
public Object put(Schema.SObjectField fieldName, Object value)
Parameters
- fieldName
- Type: Schema.SObjectField
- value
- Type: Object
Return Value
Type: Object
putSObject(String, sObject)
Signature
public sObject putSObject(String fieldName, sObject value)
Return Value
Type: sObject
putSObject(Schema.sObjectType, sObject)
Signature
public sObject putSObject(Schema.sObjectType fieldName, sObject value)
Parameters
- fieldName
- Type: Schema.SObjectType
- value
- Type: sObject
Return Value
Type: sObject
setOptions(Database.DMLOptions)
Signature
public Void setOptions(database.DMLOptions DMLOptions)
Parameters
- DMLOptions
- Type: Database.DMLOptions
Return Value
Type: Void