• Anand TripathiSBI
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 13
    Replies
Controller:-
public with sharing class LeadMassAssignController {
    /**
     * Get a list of available users to present for the selection of a new
     * lead owner.
     *
     * @return a list of User objects representing available, selectable users
     */
    
    @AuraEnabled
    public static List<User> getAvailableUsers() {
        return [
            SELECT Id, Name
            FROM User
            WHERE IsActive = TRUE 
            ORDER BY FirstName, LastName
        ];
    }

    /**
     * Assign a new owner to a given list of leads.
     *
     * @param  ownerId The User ID of the new lead owner to be assigned
     * @param  leadIds The list of Lead IDs for leads to reassign
     * @return the list of updated leads
     */
    @AuraEnabled
    public static List<Lead> assignOwner(Id ownerId, List<Id> leadIds) {
        List<Lead> leads = new List<Lead>();

        for (Id theLeadId : leadIds) {
            leads.add(new Lead(Id = theLeadId, OwnerId = ownerId));
        }

        update leads;
        return leads;
    }
    
}

// .cmp//
<aura:component controller="LeadMassAssignController" >
    <aura:attribute name="availableUsers" type="User[]" default="[]" />
    <aura:attribute name="leads" type="Lead[]" default="[]" 
                      description="Leads passed from a StandardSetController" />
  <aura:attribute name="ownerId" type="String" default="" />
  
  <aura:handler name="init" value="{!this}" action="{!c.handleInit}" />

  <!-- PAGE HEADER -->
  <div class="slds-page-header" role="banner">
    <div class="slds-grid">
      <div class="slds-col slds-has-flexi-truncate">
      
        <!-- HEADING AREA -->
        <div class="slds-media slds-no-space slds-grow">
          <div class="slds-media__figure">
            <lightning:icon iconName="standard:lead" alternativeText="Lead Icon" />
          </div>
          <div class="slds-media__body">
            <p class="slds-text-title--caps slds-line-height--reset">Leads</p>
            <h1 class="slds-page-header__title slds-truncate"
                title="Change Owner">Change Owner</h1>
          </div>
        </div>
        <!-- / HEADING AREA -->

      </div>
      <div class="slds-col slds-no-flex slds-grid slds-align-top">
        <form class="slds-form--inline">
          <div class="slds-form-element">
            <lightning:select name="owner" label="New Owner" value="{!v.ownerId}">
                <option value="" text="--None--"></option>
                <aura:iteration items="{!v.availableUsers}" var="user">
                    <option value="{!user.Id}" text="{!user.Name}"></option>
                </aura:iteration>
            </lightning:select>
          </div>
          <div class="slds-form-element">
            <button class="slds-button slds-button--brand"
                    type="button" onclick="{!c.handleAssignButtonPress}">Assign</button>
          </div>
        </form>
      </div>
    </div>

    <div class="slds-grid">
      <div class="slds-col slds-align-bottom slds-p-top--small">
        <p class="slds-text-body--small slds-page-header__info">
          Select a new owner, then tap <b>Assign</b>
        </p>
      </div>
    </div>
  </div>
  <!-- / PAGE HEADER -->

  <!-- DATA TABLE -->
  <table class="slds-table slds-table--bordered slds-table--cell-buffer slds-no-row-hover">
    <thead>
      <tr class="slds-text-heading--label">
        <th scope="col" style="width:60px"><!-- Row Number --></th>
        <th scope="col" style="width:32px">
          <label class="slds-checkbox">
            <input type="checkbox" checked="true" disabled="true" />
            <span class="slds-checkbox--faux"></span>
          </label>
        </th>
        <th scope="col">LeadName</th>
        <th scope="col">Owner Name</th>
      </tr>
    </thead>
    <tbody>
      <aura:iteration items="{!v.leads}" var="theLead" indexVar="i">
        <tr>
          <th scope="row">{!i + 1}</th>
          <td>
            <label class="slds-checkbox">
              <input type="checkbox" checked="True" disabled="" />
                
              <span class="slds-checkbox--faux"></span>
            </label>
          </td>
          <td>{!theLead.Name}</td>
          <td>{!theLead.Owner.Name}</td>
        </tr>
      </aura:iteration>
    </tbody>
  </table>
  <!-- / DATA TABLE -->

</aura:component>

//controller.js//
({
  handleAssignButtonPress : function(component, event, helper) {
    var ownerId = component.get("v.ownerId");
    console.log("ownerId: %o", ownerId);

    var leads = component.get("v.leads");
    console.log("leads: %o", leads);

    var leadIds = [];
    leads.forEach(function(lead) {
      leadIds.push(lead.Id);
    });

    helper.assignOwner(component, ownerId, leadIds, function() {
      history.back();
    });
  },
  handleInit : function(component, event, helper) {
    helper.refreshOwnerOptions(component, helper);
  }
})
//Helper //
({
  assignOwner : function(component, ownerId, leadIds,
                         successCallback, errorCallback) {
    
    var action = component.get("c.assignOwner");

    action.setParams({
      ownerId: ownerId,
      leadIds: leadIds
    });

    action.setCallback(this, function(response) {
      console.log("response: %o", response);

      if (response.getState() === "SUCCESS") {
        if (successCallback) {
          successCallback();
        }
        else {
          alert("success");
        }
      }
      else if (response.getState() === "ERROR") {
        if (errorCallback) {
          errorCallback();
        }
        else {
          alert("error");
        }
      }
    });

    $A.enqueueAction(action);
  },
  refreshOwnerOptions : function(component, helper) {
    var action = component.get("c.getAvailableUsers");

    action.setCallback(this, function(response) {
      console.log("response: %o", response);

      if (response.getState() === "SUCCESS") {
        component.set("v.availableUsers", response.getReturnValue());
      }
      else if (response.getState() === "ERROR") {
        alert("error");
      }
    });

    $A.enqueueAction(action);
  }
})

My component Screen
Leads and Owner name are not visible
How to change owner of record(using List of active users in org) in aura component? I am trying to change the owner of the lead to available users in my org using aura component.
I want to display change owner button on my aura page and when i click thne list of users will poped up. And Now I can assign the lead to new owner. My code is given below.Please correct me.
*ChangeOwner.cmp*
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" controller="ChangeOwner" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
*Controller*
 ({
 doInit : function(component, event, helper) {
        var leadId = component.get("v.recordId");
        var action = component.get("c.changeOwnerMethod");
        action.setParams({
            leadId : leadId
        });
        action.setCallback(this, function(response) {
            if(response.getState() === "SUCCESS") {
                console.log("Lead Owner Changed To Current login User");
             var rec = response.getReturnValue();
             console.log(rec.OwnerId);
            }
        });
        $A.enqueueAction(action);
        $A.get('e.force:refreshView').fire();
     $A.get("e.force:closeQuickAction").fire();
 }
})
//Apex Class//
public class ChangeOwner {
 @AuraEnabled
    public static Lead changeOwnerMethod(Id leadId) {
        if(leadId != null) {
            Lead l = [SELECT OwnerId FROM Lead WHERE Id = :leadId];
         l.OwnerId = UserInfo.getUserId();
            update l;
            return l;
        }
        return null;
    }

}
My Code is here:-
public class LeadSearchFilter {
@AuraEnabled
    public static List<Lead> showAllAccs()
    {
        return [select name , company ,Email,Status,Lead_Age__c from Lead];
    }
    @AuraEnabled
    public static List<Lead> showFilterAccs(string acName)
    {
        
        return [select name , company , Email,status,Lead_Age__c from Lead 
                where name like :'%'+acName+'%' or status like :'%'+acName+'%' or Lead_Age__c like: '% (123) %'];
        
    }
}

I am getting this error:-This is My controller class
I want to dispaly a buttuon for search where I can select lead status. If I select open then all the open leads will displayed.
//Component//
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" controller="LeadSearchFilter" access="global" >
    <aura:attribute name="accs" type="Account[]"></aura:attribute>
    
    <aura:handler name="init" value="{!this}" action="{!c.showAllAccounts}"></aura:handler>
    <!--<lightning:input label="Search Account" placeholder="Search account by name or rating or industry" aura:id="txt1" onchange="{!c.showFilterAccount}"></lightning:input>-->
<lightning:select aura:id="select" name="select" label="Select Lead" onchange="{! c.showAllAccounts }">
    <option value="">choose one...</option>
    <option value="apple">status</option>
    <option value="pumpkin">Name</option>
        <option value="pumpkin">Lead Stage</option>
 
</lightning:select>
    <br/><br/>
<table border="1">
  <tr>
    <th>Name</th>
    <th>Company</th>
    <th>Status</th>
      <th>Email</th>
      
  </tr>
    <aura:iteration items="{!v.accs}" var="acc">
  <tr>
    <td>{!acc.Name}</td>
    <td>{!acc.Company}</td>
    <td>{!acc.Status}</td>
      <td>{!acc.Email}</td>
      
  </tr>
    </aura:iteration>
</table>

</aura:component>
//Apex Class//
public class LeadSearchFilter {
@AuraEnabled
    public static List<Lead> showAllAccs()
    {
        return [select name , company ,Email,Status from Lead];
    }
    @AuraEnabled
    public static List<Lead> showFilterAccs(string acName)
    {
        return [select name , company , Email,status from Lead 
                where name like :'%'+acName+'%' or status like :'%'+acName+'%'];
    }
}

//Controller//
({
    showAllAccounts : function(component, event, helper) {
        var action = component.get("c.showAllAccs");
        
        action.setCallback(this,function(response){
            
            var state = response.getState();
            
            if(state=='SUCCESS')
            {
                component.set("v.accs",response.getReturnValue());
            }
            else{
                alert('errror '+state);
            }
            
        });
        
        $A.enqueueAction(action);
    },
    showFilterAccount: function(component, event, helper) {
        var action = component.get("c.showFilterAccs");
        var n = component.find("txt1").get("v.value");
        action.setParams({"acName":n});
        
        action.setCallback(this,function(response){
            
            var state = response.getState();
            
            if(state=='SUCCESS')
            {
                component.set("v.accs",response.getReturnValue());
            }
            else{
                alert('errror '+state);
            }
            
        });        
        
        $A.enqueueAction(action);
    }
})
When i assign the lead to new owner(new user) then task like call a log(pending event) should also be assigned to this user.
I am trying to write a trigger. Which will update the name of Account field (after insert) AccountName+xyz. But its not working. my code is here.
trigger SufixAdd on Account (after insert) {
    List<account> accs=Trigger.New;
    for(account ac:Trigger.New)
    {
        if(ac.name!=Null)
        {
            ac.name=ac.name+'xyz';
        }
    }

}
I am inserting new record using apex code. My code is correct. But whenever I check this new record in my org by clicking on Account tab the record is not displaying. Can you help me. I inserted the record using VF and clicked on Account tab . There is no new record only old accounts are there. why this happening.
How to validate a name field(shuold accept only characters and phone) field(shoul accept only numbers) usign Triggers? can anyone write the code for this?
Controller:-
public with sharing class LeadMassAssignController {
    /**
     * Get a list of available users to present for the selection of a new
     * lead owner.
     *
     * @return a list of User objects representing available, selectable users
     */
    
    @AuraEnabled
    public static List<User> getAvailableUsers() {
        return [
            SELECT Id, Name
            FROM User
            WHERE IsActive = TRUE 
            ORDER BY FirstName, LastName
        ];
    }

    /**
     * Assign a new owner to a given list of leads.
     *
     * @param  ownerId The User ID of the new lead owner to be assigned
     * @param  leadIds The list of Lead IDs for leads to reassign
     * @return the list of updated leads
     */
    @AuraEnabled
    public static List<Lead> assignOwner(Id ownerId, List<Id> leadIds) {
        List<Lead> leads = new List<Lead>();

        for (Id theLeadId : leadIds) {
            leads.add(new Lead(Id = theLeadId, OwnerId = ownerId));
        }

        update leads;
        return leads;
    }
    
}

// .cmp//
<aura:component controller="LeadMassAssignController" >
    <aura:attribute name="availableUsers" type="User[]" default="[]" />
    <aura:attribute name="leads" type="Lead[]" default="[]" 
                      description="Leads passed from a StandardSetController" />
  <aura:attribute name="ownerId" type="String" default="" />
  
  <aura:handler name="init" value="{!this}" action="{!c.handleInit}" />

  <!-- PAGE HEADER -->
  <div class="slds-page-header" role="banner">
    <div class="slds-grid">
      <div class="slds-col slds-has-flexi-truncate">
      
        <!-- HEADING AREA -->
        <div class="slds-media slds-no-space slds-grow">
          <div class="slds-media__figure">
            <lightning:icon iconName="standard:lead" alternativeText="Lead Icon" />
          </div>
          <div class="slds-media__body">
            <p class="slds-text-title--caps slds-line-height--reset">Leads</p>
            <h1 class="slds-page-header__title slds-truncate"
                title="Change Owner">Change Owner</h1>
          </div>
        </div>
        <!-- / HEADING AREA -->

      </div>
      <div class="slds-col slds-no-flex slds-grid slds-align-top">
        <form class="slds-form--inline">
          <div class="slds-form-element">
            <lightning:select name="owner" label="New Owner" value="{!v.ownerId}">
                <option value="" text="--None--"></option>
                <aura:iteration items="{!v.availableUsers}" var="user">
                    <option value="{!user.Id}" text="{!user.Name}"></option>
                </aura:iteration>
            </lightning:select>
          </div>
          <div class="slds-form-element">
            <button class="slds-button slds-button--brand"
                    type="button" onclick="{!c.handleAssignButtonPress}">Assign</button>
          </div>
        </form>
      </div>
    </div>

    <div class="slds-grid">
      <div class="slds-col slds-align-bottom slds-p-top--small">
        <p class="slds-text-body--small slds-page-header__info">
          Select a new owner, then tap <b>Assign</b>
        </p>
      </div>
    </div>
  </div>
  <!-- / PAGE HEADER -->

  <!-- DATA TABLE -->
  <table class="slds-table slds-table--bordered slds-table--cell-buffer slds-no-row-hover">
    <thead>
      <tr class="slds-text-heading--label">
        <th scope="col" style="width:60px"><!-- Row Number --></th>
        <th scope="col" style="width:32px">
          <label class="slds-checkbox">
            <input type="checkbox" checked="true" disabled="true" />
            <span class="slds-checkbox--faux"></span>
          </label>
        </th>
        <th scope="col">LeadName</th>
        <th scope="col">Owner Name</th>
      </tr>
    </thead>
    <tbody>
      <aura:iteration items="{!v.leads}" var="theLead" indexVar="i">
        <tr>
          <th scope="row">{!i + 1}</th>
          <td>
            <label class="slds-checkbox">
              <input type="checkbox" checked="True" disabled="" />
                
              <span class="slds-checkbox--faux"></span>
            </label>
          </td>
          <td>{!theLead.Name}</td>
          <td>{!theLead.Owner.Name}</td>
        </tr>
      </aura:iteration>
    </tbody>
  </table>
  <!-- / DATA TABLE -->

</aura:component>

//controller.js//
({
  handleAssignButtonPress : function(component, event, helper) {
    var ownerId = component.get("v.ownerId");
    console.log("ownerId: %o", ownerId);

    var leads = component.get("v.leads");
    console.log("leads: %o", leads);

    var leadIds = [];
    leads.forEach(function(lead) {
      leadIds.push(lead.Id);
    });

    helper.assignOwner(component, ownerId, leadIds, function() {
      history.back();
    });
  },
  handleInit : function(component, event, helper) {
    helper.refreshOwnerOptions(component, helper);
  }
})
//Helper //
({
  assignOwner : function(component, ownerId, leadIds,
                         successCallback, errorCallback) {
    
    var action = component.get("c.assignOwner");

    action.setParams({
      ownerId: ownerId,
      leadIds: leadIds
    });

    action.setCallback(this, function(response) {
      console.log("response: %o", response);

      if (response.getState() === "SUCCESS") {
        if (successCallback) {
          successCallback();
        }
        else {
          alert("success");
        }
      }
      else if (response.getState() === "ERROR") {
        if (errorCallback) {
          errorCallback();
        }
        else {
          alert("error");
        }
      }
    });

    $A.enqueueAction(action);
  },
  refreshOwnerOptions : function(component, helper) {
    var action = component.get("c.getAvailableUsers");

    action.setCallback(this, function(response) {
      console.log("response: %o", response);

      if (response.getState() === "SUCCESS") {
        component.set("v.availableUsers", response.getReturnValue());
      }
      else if (response.getState() === "ERROR") {
        alert("error");
      }
    });

    $A.enqueueAction(action);
  }
})

My component Screen
Leads and Owner name are not visible
My Code is here:-
public class LeadSearchFilter {
@AuraEnabled
    public static List<Lead> showAllAccs()
    {
        return [select name , company ,Email,Status,Lead_Age__c from Lead];
    }
    @AuraEnabled
    public static List<Lead> showFilterAccs(string acName)
    {
        
        return [select name , company , Email,status,Lead_Age__c from Lead 
                where name like :'%'+acName+'%' or status like :'%'+acName+'%' or Lead_Age__c like: '% (123) %'];
        
    }
}

I am getting this error:-This is My controller class
I am trying to write a trigger. Which will update the name of Account field (after insert) AccountName+xyz. But its not working. my code is here.
trigger SufixAdd on Account (after insert) {
    List<account> accs=Trigger.New;
    for(account ac:Trigger.New)
    {
        if(ac.name!=Null)
        {
            ac.name=ac.name+'xyz';
        }
    }

}
I am inserting new record using apex code. My code is correct. But whenever I check this new record in my org by clicking on Account tab the record is not displaying. Can you help me. I inserted the record using VF and clicked on Account tab . There is no new record only old accounts are there. why this happening.
How to validate a name field(shuold accept only characters and phone) field(shoul accept only numbers) usign Triggers? can anyone write the code for this?