Created
October 21, 2015 11:19
-
-
Save pchittum/ad587e38a187ebce93d2 to your computer and use it in GitHub Desktop.
Using Lightning Components force:outputField or force:inputField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public with sharing class AccountViewEditService { | |
| @AuraEnabled | |
| public static Account fetchAccount(Id acctId){ | |
| Account newAcct; | |
| try { | |
| System.debug('querying for account id: ' + acctId); | |
| newAcct = [SELECT Id, Name, Type, ParentId, BillingStreet, BillingCity, BillingState, | |
| BillingPostalCode, BillingCountry, BillingLatitude, BillingLongitude, | |
| BillingGeocodeAccuracy, Phone, Fax, AccountNumber, Website, PhotoUrl, | |
| Sic, Industry, AnnualRevenue, NumberOfEmployees, Ownership, TickerSymbol, | |
| Description, Rating, Site, OwnerId, CreatedDate, CreatedById, | |
| LastModifiedDate, LastModifiedById, LastActivityDate, LastViewedDate, | |
| LastReferencedDate, Jigsaw, JigsawCompanyId, CleanStatus, AccountSource, | |
| DunsNumber, Tradestyle, NaicsCode, NaicsDesc, YearStarted, SicDesc, | |
| DandbCompanyId, ConnectionReceivedId, ConnectionSentId, CustomerPriority__c, | |
| SLA__c, Active__c, NumberofLocations__c, UpsellOpportunity__c, SLASerialNumber__c, | |
| SLAExpirationDate__c, Customer_ID__c, opportunity_count__c, ShippingStreet, | |
| ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, ShippingLatitude, | |
| ShippingLongitude, ShippingGeocodeAccuracy | |
| FROM Account | |
| WHERE Id = : acctId]; | |
| } catch (QueryException e){ | |
| System.debug('No record was found for the Id provided. Returning null account'); | |
| } | |
| return newAcct; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ({ | |
| doInit : function(component, event, helper) { | |
| var fetchAccount = component.get('c.fetchAccount'); | |
| fetchAccount.setParam('acctId','00124000003c9qQ');// <-- for testing verified this is valid account id | |
| fetchAccount.setCallback(this, function(resp){ | |
| if (component.isValid()){ | |
| if (resp.getState() === 'SUCCESS'){ | |
| console.log('callback success and component is valid'); | |
| var acct = resp.getReturnValue(); | |
| console.log(acct.Name) | |
| component.set('v.accountRecord',acct); | |
| } else { | |
| console.log('request failed'); | |
| console.log(resp); | |
| console.log(resp.error[0]); | |
| } | |
| } else { | |
| console.log('component unavailable on callback'); | |
| } | |
| },'ALL'); | |
| $A.enqueueAction(fetchAccount); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <aura:component controller="AccountViewEditService" implements="force:appHostable" > | |
| <aura:attribute name="accountRecord" type="Account" /> | |
| <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
| <!-- these throw an error --> | |
| <force:inputField value="{!v.accountRecord.Name}"/> | |
| <force:inputField value="{!v.accountRecord.Type}"/> | |
| <force:inputField value="{!v.accountRecord.AnnualRevenue}"/> | |
| <force:inputField value="{!v.accountRecord.BillingCountry}"/> | |
| <!-- these do too | |
| <force:outputField value="{!v.accountRecord.Name}"/> | |
| <force:outputField value="{!v.accountRecord.Type}"/> | |
| <force:outputField value="{!v.accountRecord.AnnualRevenue}"/> | |
| <force:outputField value="{!v.accountRecord.BillingCountry}"/> | |
| these do not | |
| <ui:inputText value="{!v.accountRecord.Name}"/> | |
| <ui:inputSelect value="{!v.accountRecord.Type}"/> | |
| <ui:inputNumber value="{!v.accountRecord.AnnualRevenue}"/> | |
| <ui:inputText value="{!v.accountRecord.BillingCountry}"/> | |
| --> | |
| </aura:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment