Posts

Showing posts with the label Apex

Future Callout with apex trigger for a webservice

 if(System.IsBatch() == false && System.isFuture() == false){   Error if this above condition is not used in trigger: System.AsyncException: Future method cannot be called from a future or batch method: herokuapp.animalname(String) Animal__c is a string field to update a value of o index from the webservice call. Trigger:  trigger herokuapp_account on Account (after update) {     for(account a: trigger.new)     {         if(System.IsBatch() == false && System.isFuture() == false){              if(trigger.isUpdate)             {                 herokuapp.animalname(a.id);             }         }     } } Trigger Handler  public with sharing class herokuapp {     @future(callout=true)     public static void animalname(strin...

Updating Date while deactivating user

 Create a custom field of text and date. /* While deactivating a user on User Object update field on msg__c and deactivatedate__c with current dd*/   Apex Class public class deactivateHelper{       public static Boolean isFirstTime = true;     public static void updateUser(Set<id> pxyUsrId){                  system.debug('====='+pxyUsrId);         //Getting the Id for the user         Id userId = [select id,msg__c from User where id in: pxyUsrId limit 1].Id ;        //  List<User> userListToDeactivate = [select id,msg__c from User where id in: ids];                          List<User> uselst = new List<User>();         if(pxyUsrId.size() > 0 ){             for(user us : [SELECT Id, msg__c,deactivated...

Activating/deactivating trigger based on custom setting

  Create a custom setting with Name  TriggerSupport; and Field Checkbox with Label  TriggerOff Click on Manage --->  Set Default value as true  Code for getting the custom setting value TriggerSupport__c support = TriggerSupport__c.getInstance('TriggerOff__c'); system.debug('support'+support.TriggerOff__c); Output:  USER_DEBUG [3]|DEBUG|supporttrue

Showing Apex Error on UI for Lightning WebComponents(lwc)

Image
 Template: <template>      <lightning-card   title = "Showing error From Apex" >          <lightning-button   label = "Get Contacts"   onclick = {handleGetContacts} ></lightning-button>                   <template   if:true = {error} >              <c-error-panel   errors = {error} ></c-error-panel>          </template>      </lightning-card> </template> Js:      import  {  LightningElement , wire  }  from   'lwc' ; //importing from apex import  srchval  from   '@salesforce/apex/showErrorMsg.showError' ; export default   class   ShowErrorfromApex ...

Using Wire Apex

Using Wire Apex Scenario 1: Using Wire Apex: AccountCountroller.html <template>      <lightning-card title= 'Account' >          <ul>          <lightning-card title= "Account List" >              <div class= "slds-m-around_medium" >                  <template if:true= {accounts.data} >                      <template for:each= {accounts.data}  for:item= "acc" >                          <p key= {acc.Id} > {acc.Name} ...