Newer Version Available
Considerations
- Lightning Experience
- Salesforce app
- Lightning Communities
- Lightning Out
- Lightning Components for Visualforce
- Standalone Lightning apps
- Lightning for Gmail
- Lightning for Outlook
Lightning Data Service supports primitive DML operations—create, read, update, and delete. It operates on one record at a time, which you retrieve or modify using the record ID. Lightning Data Service supports spanned fields with a maximum depth of five levels. Support for working with collections of records or for querying for a record by anything other than the record ID isn’t available. If you must support higher-level operations or multiple operations in one transaction, use standard @AuraEnabled Apex methods.
Lightning Data Service shared data storage provides notifications to all components that use a record whenever a component changes that record. It doesn’t notify components if that record is changed on the server, for example, if someone else modifies it. Records changed on the server aren’t updated locally until they’re reloaded. Lightning Data Service notifies listeners about data changes only if the changed fields are the same as in the listener’s fields or layout.
- Loads record data progressively.
- Caches results on the client.
- Invalidates cache entries when dependent Salesforce data and metadata changes.
- Optimizes server calls by bulkifying and deduping requests.
Use Base Components
To work with record data, use the following base components.
- lightning:recordForm
- lightning:recordEditForm
- lightning:recordViewForm
- Create a metadata-driven UI or form-based UI similar to the record detail page in Salesforce.
- Display record values based on the field metadata.
- Display or hide localized field labels.
- Display the help text on a custom field.
- Perform client-side validation and enforce validation rules.
To create a custom UI or if you don’t need a metadata-driven UI, use the force:recordData component.
When using force:recordData, load the data once and pass it to child components as attributes. This approach reduces the number of listeners and minimizes server calls, which improves performance and ensures that your components show consistent data.
For more information, see Lightning Action Examples.
- An Aura or Lightning web component mutates the record.
- The Lightning Data Service cache entry expires and then a component built on Lightning Data Service triggers a read. The cache entry and the Lightning web component must be in the same browser and app (for example Lightning Experience) for the same user.
Supported Objects
Lightning Data Service supports custom objects and the following.
- Account
- AccountBrand
- AccountContactRelation
- AccountForecast
- AcctMgrPeriodicTargetDstr
- AcctMgrTarget
- AcctMgrTargetDstr
- AccountProductForecast
- AccountProductPeriodForecast
- AccountParticipant
- AccountPartner
- AccountTeamMember
- ActionCadence
- ActionPlan
- ActionPlanItem
- ActionPlanTemplate
- ActionPlanTemplateItem
- ActionPlanTemplateItemValue
- ActionPlanTemplateVersion
- Address
- AiVisitRecommendation
- AiVisitRecommendRequest
- AssessmentIndDefinedValue
- AssessmentIndValue
- AssessmentTask
- AssessmentTaskContentDocument
- AssessmentTaskOrder
- Asset
- AssetRelationship
- AssetStatePeriod
- AssetWarranty
- AssignedResource
- AttachedContentNote
- BasicDataRecord
- BusinessAccount
- BusinessLicenseApplication
- BusinessMilestone
- BusinessProfile
- Campaign
- CampaignMember
- CareBarrier
- CareBarrierType
- CarePgmProvHealthcareProvider
- CareProgram
- CareProgramEnrollee
- CareRegisteredDevice
- Case
- Claim
- ClaimCase
- ClaimItem
- ClaimParticipant
- Contact
- ContactRequest
- ContentDocument
- ContentNote
- ContentVersion
- ContentWorkspace
- Contract
- ContractContactRole
- ContractLineItem
- CoverageType
- Custom Object
- CustomerProperty
- DataExportDefinition
- DataStreamDefinition
- DeleteEvent
- DeliveryTask
- DigitalSignature
- ElectronicMediaGroup
- Employee
- EmployeeAsset
- EmployeeContact
- EmployeeJob
- EmployeeJobPosition
- EmployeeOrganization
- Entitlement
- EntityArchivingSetup
- EnvironmentHubMember
- Examination
- Expense
- ExpenseReport
- ExpenseReportEntry
- HealthCareDiagnosis
- HealthCareProcedure
- HealthcareProvider
- Image
- IndividualApplication
- InspectionAssessmentInd
- InsuranceClaimAsset
- InsurancePolicy
- InsurancePolicyAsset
- InsurancePolicyCoverage
- InsurancePolicyMemberAsset
- InsurancePolicyParticipant
- InsuranceProfile
- JobFamily
- JobPosition
- JobProfile
- KnowledgeArticleVersion
- Lead
- LicensingRequest
- ListEmail
- LoanApplicant
- LoanApplicantAddress
- LoanApplicantDeclaration
- LoanApplicantEmployment
- LoanApplicantIncome
- LoanApplicationAsset
- LoanApplicationFinancial
- LoanApplicationLiability
- LoanApplicationProperty
- LoanApplicationTitleHolder
- Location
- LoyaltyBenefit
- LoyaltyBenefitType
- LoyaltyLedger
- LoyaltyProgram
- LoyaltyProgramCurrency
- LoyaltyProgramMember
- LoyaltyProgramPartner
- LoyaltyTier
- LoyaltyTierBenefit
- LoyaltyTierGroup
- MaintenanceAsset
- MaintenancePlan
- MaintenanceWorkRule
- MarketingAction
- MarketingResource
- MessagingChannel
- MessagingEndUser
- MessagingSession
- MsgChannelLanguageKeyword
- Note
- OccupationLicenseApplication
- OperatingHours
- OperatingHoursHoliday
- Opportunity
- OpportunityLineItem
- OpportunityLineItemSchedule
- OpportunityParticipant
- OpportunityPartner
- OpportunityTeamMember
- Order
- OrderItem
- OrderItemSummaryChange
- OrderSummary
- OrgMetric
- OrgMetricScanSummary
- OrgMetricScanResult
- OtherComponentTask
- Partner
- PersonAccount
- PersonExamination
- PersonLifeEvent
- PgmRebateTypBnftMapping
- PreliminaryApplicationRef
- PriceAdjustmentSchedule
- Pricebook2
- PricebookEntry
- Producer
- ProducerPolicyAssignment
- Product2
- Product2DataTranslation
- ProductAttribute
- ProductAttributeSet
- ProductAttributeSetItem
- ProductAttributeSetProduct
- ProductCategoryDataTranslation
- ProductCategoryMedia
- ProductCoverage
- ProductMedia
- ProductServiceCampaign
- ProductTransfer
- ProductWarrantyTerm
- ProgramRebateType
- ProgramRebateTypeBenefit
- ProgramRebateTypeFilter
- ProgramRebateTypePayout
- ProgramRebateTypPayoutSrc
- Promotion
- Quote
- QuoteDocument
- QuoteLineItem
- RebateMemberProductAggregate
- RebatePayment
- RebatePayoutAdjustment
- RebateProgram
- RebateProgramMember
- RebateProgramMemberPayout
- RebateProgramPayoutPeriod
- ReceivedDocument
- RecordAction
- RecordsetFilterCriteria
- RecordsetFilterCriteriaRule
- RecordType
- RegulatoryAuthority
- RegulatoryAuthorizationType
- RegulatoryCode
- RegulatoryCodeAssessmentInd
- RegulatoryCodeViolation
- ResidentialLoanApplication
- ResourceAbsence
- ResourcePreference
- RetailVisitKpi
- RetailVisitWorkTask
- RetailVisitWorkTaskOrder
- SalesAgreement
- SalesAgreementProduct
- SecuritiesHolding
- ServiceAppointment
- ServiceContract
- ServiceCrew
- ServiceCrewMember
- ServiceResource
- ServiceResourceCapacity
- ServiceResourceSkill
- ServiceTerritory
- ServiceTerritoryLocation
- ServiceTerritoryMember
- SetupAssistantStep
- Shift
- ShiftPattern
- Shipment
- SignatureTask
- SignatureTaskLineItem
- SkillRequirement
- SocialPost
- SurveyInvitation
- SurveyResponse
- SurveySubject
- Tenant
- TimeSheet
- TimeSheetEntry
- TimeSlot
- TrainingCourseParticipant
- TransactionJournal
- TrnCourse
- UsageEntitlement
- UsageEntitlementPeriod
- User
- ViolationEnforcementAction
- ViolationType
- Visit
- VisitedParty
- Visitor
- VoiceCall
- WarrantyTerm
- WaveAutoInstallRequest
- WebStoreCatalog
- WebStoreSearchProdSettings
- WorkerCompCoverageClass
- WorkContract
- WorkOrder
- WorkOrderLineItem
- WorkType