Tuesday 17 July 2018


Customize error message for trigger and display error message below the field

This Post demonstrates how to display error message in particular field level.

SObject SomeRecord;
SomeRecord.SomeField__c.addError('Custom Message');
//or
SomeRecord.someField__c.addError(someException);

Note:

We cannot add it to a field dynamically. This error mapping can only be done with a hard-coded field.


aura:method in Salesforce


  • This enables you to directly call a method in a component’s client-side controller instead of firing and handling a component event.
  • Using <aura:method> simplifies the code needed for a parent component to call a method on a child component that it contains. 
ParentComp:


<aura:component description="parentComponent" access="global" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes">
    <c:childComponent aura:id="childQuestion"/>
    <button type="button" aura:id="saveAndReturn" class="slds-button" onclick="{!c.save}">Save and return
    </button>  
</aura:component>

Controller:

({
    save : function(component,helper,event){
 var childComponent = component.find("childQuestion");
        childComponent.getScoreMethod('aa','bb','cc');
    }
})


childComponent.cmp


<aura:component description="childComponent" access="global">
    <aura:method name="getScoreMethod" action="{!c.calcScore}" access="PUBLIC">
        <aura:attribute name="contactId" type="String" />
        <aura:attribute name="contactName" type="String"  />
        <aura:attribute name="recordId" type="String"  />
    </aura:method>

</aura:component> 


({
    calcScore : function(component,event,helper){
        var args = event.getParam("arguments");
        var contactId = args.contactId;
        var contactName = args.contactName;
        var recod=args.recordId;
       alert('Inside Calc Score: ' + contactId + ' - ' + contactName+'-'+recod);
    }
})


Application:


<aura:application >
 <c:ParentComp/>
</aura:application>


Custom setting Setting type not visible




You Can enable list custom setting schema Setting Page
Setup > schema Setting Page > List custom Setting




After Enabling,
  


    




List has no rows for assignment to SObject  error

 Consider following query:
   
      id p;
      user u = [SELECT Id from user where Name = :username];
      if (u != null)
      p = u.Id;

  •  The above code will fail if there is no user record with the matching username. It doesn't actually return a null.


 It would be safer to do the following:

    id p;
     user[] userlist = [SELECT Id from user where Name = :username];
     if (userlist.size() > 0)
       p = userlist[0].Id;