• Vidol Chalamov
  • NEWBIE
  • 25 Points
  • Member since 2018
  • Software Engineer
  • AptSystems

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
I want to update Account.Name with ( FirstName__C + LastName__C) whenever FirstName__C or LastName__C is changed or new account is created.

Workflow/process builder/trigger will not work as it will work when event is raised and Account.Name is mandatory field. Any suggestion. 
I want to update Account.Name with ( FirstName__C + LastName__C) whenever FirstName__C or LastName__C is changed or new account is created.

Workflow/process builder/trigger will not work as it will work when event is raised and Account.Name is mandatory field. Any suggestion. 
Apex code 

public with sharing class getopportunity {
public ApexPages.StandardSetController opty {
get {
 if (opty==null)
 {
 ApexPages.StandardSetController opty = New ApexPages.StandardSetController (Database.getquerylocator([select Name, CloseDate FROM Opportunity])); } 
 return opty;} 
 set;} 
 public List<Opportunity> getOpportunities() { 
 return (List<Opportunity>) opty.getRecords();} 
 }

Getting the following error when I m trying to create a MAP out of Account object.
There are many Accounts in the ORG but I need to get and Map of all so cross check a condition on trigger and update few accounts based on the conditions..

But I need to get the accounts MAP first to get the existing Account records, is there a way to get all the accounts

Sharing the code below...

Requesting please let me how to proceed with this..

 

public with sharing class AccountReleationShipTriggerHandler {    
    public static void getAccountFromTrigger(List<Account_Relationships__c>  lstAccountRelation)
    {        
        System.debug('>>>>>>> lstAccountRelation : '+lstAccountRelation.size());
        ID rtId = [SELECT Id FROM RecordType WHERE SobjectType='Account' and developerName='Site'].id;        
        Map<ID, Account> allAccountMap = new Map<ID, Account>([SELECT Id, Name, Portfolio_Type__c, Source_Zone__c, RecordTypeID FROM Account]);        

        for (Account_Relationships__c ar : lstAccountRelation)
        {
            // will perform the operations here... 
            // As here I need to refer the MAP to find the account details and update
..
            System.debug('test ar Source_Account__c : '+ ar.Source_Account__c);
            System.debug('test ar Related_Account__c : '+ ar.Related_Account__c);
            System.debug('test ar Type__c : '+ ar.Type__c);        
        }         
   }    
}

 

Getting following error : 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger trig_AccountUpdate caused an unexpected exception, contact your administrator: trig_AccountUpdate: execution of AfterInsert caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Class.AccountReleationShipTriggerHandler.getAccountFromTrigger: line 6, column 1