• badri nath 9
  • NEWBIE
  • 39 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
code below working not fine I am querying the records don't use soql&collections.please find that ,

trigger Trgr_duplicate_check on Account (before insert,before update) {

  //List<Account> actList=  [select id,name from Account];
   string str = 'select id ,Name from Account' ;
  
  for(Account actobj :Trigger.New){
    if(Trigger.isinsert || Trigger.isBefore){
     // for(Account actobj1 :actList){
      
       /*if(actobj1.Name == actobj.Name){
          actobj.Name.addError('Name already exits!!!');
        
        }*/
        if(str.contains(actobj.Name)){  // here require proper method to search strings for duplicates
          
                  actobj.Name.addError('Name already exits!!!');
   }
          // }
      }
   }
}
Thanks):-
Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="countRecords" >
    <aura:attribute name="contactcount" type="integer" />
     <aura:attribute name="Accountcount" type="integer" />
    <aura:attribute name="oppcount" type="integer" />
    <div style = "slds">
        <lightning:button onclick="{!c.count}" title="to get the total numbe of records" class="slds-button-sucess"  label="count" variant="brand" iconName="utility:people" iconPosition="left" /><br/>

        Totalnumber of accounts:<ui:outputText value="{!v.contactcount}" title="Totalnumber of accounts" class="slds-output"/><br/>
        Totalnumber of contacts:<ui:outputText value="{!v.Accountcount}" title="Totalnumber of contacts" class="slds-output"/><br/>
        Totalnumber of opprts:<ui:outputText value="{!v.oppcount}" title="Totalnumber of opprts"  class="slds-output"/><br/>
     </div>
</aura:component>
Controller:
({
    count : function(cpnt, event, helper) {
        var action = cpnt.get("c.getrecords");
        var accounts = cpnt.get("v.contactcount");
        var contacts = cpnt.get("v.Accountcount"); 
        var opprts = cpnt.get("v.oppcount");
        action.setParams({ 
                            "accounts": accounts,
                             "contacts": contacts ,
                              "opprts": opprts ,
                         });
        
    action.setCallback(this, function(a) {
           var state = a.getState();
            if (state === "SUCCESS") {
 
    alert("Records are counted sucessfully");
                           
            }
        });
    $A.enqueueAction(action);  

      
    }

})
Apex controller:
public class countRecords {
   /* @AuraEnabled public   integer accounts {get;set;} 
        @AuraEnabled public   integer contacts {get;set;}
        @AuraEnabled public  integer opprts {get;set;}*/
     @AuraEnabled
    Public static void getrecords(integer accounts,integer contacts, integer opprts){
        
        accounts = [select count() from Account];
        contacts = [select count() from contact];
        opprts = [select count() from Opportunitie__c];  
        system.debug('>>>>>>>>>>>'+accounts);
    }
    
}
Thanks in advance
VFpage:
<apex:page controller="c1" sidebar="false" docType="Html-5.0" id="page1"  tabStyle="account">
<apex:form >
<apex:pageBlock >

<apex:inputText value="{!name}" />
<apex:commandButton value="search" action="{!search}"/>
<apex:pageblocktable value="{!acts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.id}"/>
<apex:column value="{!a.type}"/>
</apex:pageblocktable>
</apex:pageBlock>

</apex:form>
</apex:page>




controller class:

public with sharing class c1 {
      public String name { get; set; }

    public list<account> acts { get; set; }

    public PageReference search() {
     acts=[select id,type,name from account where name like 'b%'];
        return null;
    }
}
component:
<aura:component  implements="force:appHostable"  controller = "SearchClass">
    <aura:attribute name = "search" type = "string" />
    <aura:attribute name = "accnts" type ="Account[]" />
    <ui:inputText value = "{!v.search}" class = "slds-input" placeholder = "Account Search"/>
    <lightning:button onclick = "{!c.search}"  name = "btn1" label = "Search"/>
    <aura:iteration items = "{!v.accnts}" var = "a" >
        <ui:outputText value = "{!a.Id}" />
        <ui:outputText value = "{!a.Type}" />
    </aura:iteration>
</aura:component>
controller:
({
    search : function(component, event, helper) {
        var action = component.get("c.getAccounts");
        var value1 = component.get("v.search");
        //alert(value1);
          action.setParam({ "acc"  : value1 });
                action.setCallback(this, function(response) {
            var state = response.getState();

            if (state === "SUCCESS") {
        component.set("v.accnts" ,response.getReturnValue());

                alert("From server: " + response.getReturnValue());
            }
    });
        $A.enqueueAction(action);

 }
})

serversidecontroller:
public class SearchClass {
   @AuraEnabled
    public static List<Account> getAccounts(string acc){
         string accname ;
            accname = acc ;
        list<account> actlst = new list<Account>();
         actlst = [select Id ,Type from Account where Name = 'accname' ];
        return actlst;
    } 
    
    
I have parent object plan__c when i update name field in plan__c, trigger it will update child object process__c fields ,the tigger is below ,it's not working properly.....,
trigger trgr_plan on plan__c (after insert) {

{
    List<process__c> prcList = new List<process__c>();

    for(plan__c pcc:Trigger.newMap.Values())
    {
    process__c prc=new process__c ();
      prc.name=pcc.name;
      prc.processnewname__c=pcc.name;
        prcList .add(prc);
    }
   if(prcList .size()>0)
    {
        insert prcList ;
    }
}
}
VFpage:
<apex:page controller="c1" sidebar="false" docType="Html-5.0" id="page1"  tabStyle="account">
<apex:form >
<apex:pageBlock >

<apex:inputText value="{!name}" />
<apex:commandButton value="search" action="{!search}"/>
<apex:pageblocktable value="{!acts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.id}"/>
<apex:column value="{!a.type}"/>
</apex:pageblocktable>
</apex:pageBlock>

</apex:form>
</apex:page>




controller class:

public with sharing class c1 {
      public String name { get; set; }

    public list<account> acts { get; set; }

    public PageReference search() {
     acts=[select id,type,name from account where name like 'b%'];
        return null;
    }
}
I have parent object plan__c when i update name field in plan__c, trigger it will update child object process__c fields ,the tigger is below ,it's not working properly.....,
trigger trgr_plan on plan__c (after insert) {

{
    List<process__c> prcList = new List<process__c>();

    for(plan__c pcc:Trigger.newMap.Values())
    {
    process__c prc=new process__c ();
      prc.name=pcc.name;
      prc.processnewname__c=pcc.name;
        prcList .add(prc);
    }
   if(prcList .size()>0)
    {
        insert prcList ;
    }
}
}
code below working not fine I am querying the records don't use soql&collections.please find that ,

trigger Trgr_duplicate_check on Account (before insert,before update) {

  //List<Account> actList=  [select id,name from Account];
   string str = 'select id ,Name from Account' ;
  
  for(Account actobj :Trigger.New){
    if(Trigger.isinsert || Trigger.isBefore){
     // for(Account actobj1 :actList){
      
       /*if(actobj1.Name == actobj.Name){
          actobj.Name.addError('Name already exits!!!');
        
        }*/
        if(str.contains(actobj.Name)){  // here require proper method to search strings for duplicates
          
                  actobj.Name.addError('Name already exits!!!');
   }
          // }
      }
   }
}
Thanks):-
Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="countRecords" >
    <aura:attribute name="contactcount" type="integer" />
     <aura:attribute name="Accountcount" type="integer" />
    <aura:attribute name="oppcount" type="integer" />
    <div style = "slds">
        <lightning:button onclick="{!c.count}" title="to get the total numbe of records" class="slds-button-sucess"  label="count" variant="brand" iconName="utility:people" iconPosition="left" /><br/>

        Totalnumber of accounts:<ui:outputText value="{!v.contactcount}" title="Totalnumber of accounts" class="slds-output"/><br/>
        Totalnumber of contacts:<ui:outputText value="{!v.Accountcount}" title="Totalnumber of contacts" class="slds-output"/><br/>
        Totalnumber of opprts:<ui:outputText value="{!v.oppcount}" title="Totalnumber of opprts"  class="slds-output"/><br/>
     </div>
</aura:component>
Controller:
({
    count : function(cpnt, event, helper) {
        var action = cpnt.get("c.getrecords");
        var accounts = cpnt.get("v.contactcount");
        var contacts = cpnt.get("v.Accountcount"); 
        var opprts = cpnt.get("v.oppcount");
        action.setParams({ 
                            "accounts": accounts,
                             "contacts": contacts ,
                              "opprts": opprts ,
                         });
        
    action.setCallback(this, function(a) {
           var state = a.getState();
            if (state === "SUCCESS") {
 
    alert("Records are counted sucessfully");
                           
            }
        });
    $A.enqueueAction(action);  

      
    }

})
Apex controller:
public class countRecords {
   /* @AuraEnabled public   integer accounts {get;set;} 
        @AuraEnabled public   integer contacts {get;set;}
        @AuraEnabled public  integer opprts {get;set;}*/
     @AuraEnabled
    Public static void getrecords(integer accounts,integer contacts, integer opprts){
        
        accounts = [select count() from Account];
        contacts = [select count() from contact];
        opprts = [select count() from Opportunitie__c];  
        system.debug('>>>>>>>>>>>'+accounts);
    }
    
}
Thanks in advance
component:
<aura:component  implements="force:appHostable"  controller = "SearchClass">
    <aura:attribute name = "search" type = "string" />
    <aura:attribute name = "accnts" type ="Account[]" />
    <ui:inputText value = "{!v.search}" class = "slds-input" placeholder = "Account Search"/>
    <lightning:button onclick = "{!c.search}"  name = "btn1" label = "Search"/>
    <aura:iteration items = "{!v.accnts}" var = "a" >
        <ui:outputText value = "{!a.Id}" />
        <ui:outputText value = "{!a.Type}" />
    </aura:iteration>
</aura:component>
controller:
({
    search : function(component, event, helper) {
        var action = component.get("c.getAccounts");
        var value1 = component.get("v.search");
        //alert(value1);
          action.setParam({ "acc"  : value1 });
                action.setCallback(this, function(response) {
            var state = response.getState();

            if (state === "SUCCESS") {
        component.set("v.accnts" ,response.getReturnValue());

                alert("From server: " + response.getReturnValue());
            }
    });
        $A.enqueueAction(action);

 }
})

serversidecontroller:
public class SearchClass {
   @AuraEnabled
    public static List<Account> getAccounts(string acc){
         string accname ;
            accname = acc ;
        list<account> actlst = new list<Account>();
         actlst = [select Id ,Type from Account where Name = 'accname' ];
        return actlst;
    } 
    
    
I have parent object plan__c when i update name field in plan__c, trigger it will update child object process__c fields ,the tigger is below ,it's not working properly.....,
trigger trgr_plan on plan__c (after insert) {

{
    List<process__c> prcList = new List<process__c>();

    for(plan__c pcc:Trigger.newMap.Values())
    {
    process__c prc=new process__c ();
      prc.name=pcc.name;
      prc.processnewname__c=pcc.name;
        prcList .add(prc);
    }
   if(prcList .size()>0)
    {
        insert prcList ;
    }
}
}