• Matthew Coolidge
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Greetings, I've created my external object for the Data Integration Specalist Superbadge and have configured my external ID as seen below, however, the challenge seems to not pass, indicating that the indirect lookup was not properly created. Here's how I set up the projectRef__c field, which was what I used to push data from the external object into the project object in Salesforce. Are there any steps, I need to take. Hope it helps.
User-added image


User-added image
 
I am trying to create a trigger on Contact. When a custom field Company_Name__c on Contact is populated the trigger should create an Account if it does not exist. Also the AccountId should be updated on the Contact record
I was able to do it with simple trigger code but noticed that there is a limit (Number of Query Rows: 50000). So I started trying using Queueable APEX but ran into this issue
I am not able to update the Contact records. I see the AccountId value in the debug logs but the Contact record is not updated with AccountId after the Trigger completed
Can you suggest how this can be achieved

Below is the code I am using

CreateAccountFromCompanyTrigger

trigger CreateAccountFromCompanyTrigger on Contact (before insert, after insert) {
    If(Trigger.isBefore && Trigger.isInsert)
    {
       
    //ContactTriggerClass.InsertContacts(Trigger.new); 
    ContactTriggerClass CreateContactJob = new ContactTriggerClass(Trigger.new);     
    System.enqueueJob(CreateContactJob);
               
    }//If
}

ContactTriggerClass

public class ContactTriggerClass implements Queueable  {
  
    //public List<Contact> TriggeredContactList = new List<Contact>();
    public List<Contact> TriggeredContactList;
   
    public ContactTriggerClass(List<Contact> ContactList){
        TriggeredContactList = ContactList;
       
    }//mainmethod
   
    public void execute(QueueableContext context) {
    List<Account> AcctsToCreate = new List<Account>();
    Map<String, Account> AllAccountsMap = new Map<String, Account>();
       
        for(Account acct : [Select Id, Name from Account]){
            AllAccountsMap.put(acct.Name, acct);
           
        }
   
    System.debug('AllAccountsMap:' +AllAccountsMap.size());
       
        Set<String> CompanyNameSet = new Set<String>();
        for(Contact cntct : TriggeredContactList ){
            if(!AllAccountsMap.containsKey(cntct.Company_Name__c))
                CompanyNameSet.add(cntct.Company_Name__c);
        }   
       
         if(CompanyNameSet.size() > 0){
            for(String CompanyName : CompanyNameSet)
            AcctsToCreate.add(new Account(Name = CompanyName));
        insert AcctsToCreate;
        }
       
        if(AcctsToCreate.size() > 0)
        {
            for(Account acct : AcctsToCreate)
                AllAccountsMap.put(acct.Name, acct);
        }
        System.debug('UpdatedAccountsMap' +AllAccountsMap.size()); 
       
        for(Contact cntct : TriggeredContactList){
            cntct.AccountId = AllAccountsMap.get(cntct.Company_Name__c).Id;
            System.debug('cntct record:' +cntct +cntct.AccountId);
        }
       
       
}//execute
  
   
   
}//class