• Nitish Bansal 2
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Problem Statement: (https://developer.salesforce.com/trailhead/lex_dev/lightning_components/lightning_components_apex#challenge)
Create a Lightning Component to display Case information :
  • The component must be named 'DisplayCase'.
  • The component must refer to the 'DisplayCaseController' Apex class.
  • The component must have an attribute named 'record' to hold the Case record.
  • The component must display the Subject, Description, and Status values of the 'record' attribute.
  • The client-side controller for the component must bind to the 'getCaseFromId' method of the Apex controller to fetch the value of a Case record.
  • Note that while the Apex class accepts a null and returns a default case, there are various ways to hand the ID to the controller.

Solution implemented by me:

1. Apex Class

public class DisplayCaseController {

    @AuraEnabled
    public static Case getCaseFromId(Id caseID) {
        if(caseID == null) {
            return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
        }
        
        List<Case> cases = [ SELECT Id, Subject, Description, Status from CASE where ID = :caseID ];
        
        if(cases.size() == 0) {
            return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
        } else {
            return cases[0];
        }        
    }
      
}

2. Component

<aura:component controller="DisplayCaseController" implements="force:appHostable">
    <aura:attribute name="record" type="Case"/>
    
    <ui:button label="Get Case" press="{!c.doInit}"/>
  
    <p>{!v.record.Subject}</p>
    <p>{!v.record.Description}</p> 
    <p>{!v.record.Status}</p>
    
</aura:component>

3. Controller

({
    doInit : function(component) {
        var action = component.get("c.getCaseFromId");
        
        action.setCallback(this, function(a) {
            if (a.getState() === "SUCCESS") {
                component.set("v.record", a.getReturnValue());
            } 
            else if (a.getState() === "ERROR") {
                $A.log("Errors", a.getError());
            }
        });
        
        $A.enqueueAction(action);
    }
})

4. Application

<aura:application >
    <c:DisplayCase />
</aura:application>

User-added image

ISSUE : 

Challenge not yet complete... here's what's wrong:  The client side controller is not using the return value from the 'getCaseFromId' method

Although my app works perfectly in the developer edition but trailhead doesn't accept my solution. Can someone let me know what's wrong here?
 
i have an apex class and i need to display one text field in blue color. can any one tell me how we can acheive this. if it's page we can go with style and color. but how we can do it in class..


Code:

 if(ent.Agreement_Type__c != null)
                            act.Description += '\nAgreement Type = '+ ent.Agreement_Type__c;
The result i need in blue color.