• James F
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 0
    Replies
I am sorry if this has been asked before, but I wonder what exactly can you do with Trailhead points? It doesn't appear to be useful for anything except a way to indicate you have completed a number of modules, but since its for self-learning anyway, I am not sure why it is necessary to have the points? 
Hi, 
I am new to SF and right now I am trying to create a new event sign-in flow for the nonprofit I am supporting. I was informed that the flow I want to implement cannot be done using process builder so I am looking for help on how to implement this with Apex trigger.

Requirement:
- New walk-in information is provided (email, first and last name, phone number, company name)
- Check email against existing records in Leads to see if person is already in the system from previously attended events
    ** If an existing record with same email is found, update record with new information (first and last name, phone number, company name)
    ** If not matching record with same email is found, create a new record with new information 

Any suggestion? Thank you.
whenever new application comes in from students, need to check whether student contact is already there or not, if yes then update the contact record with any new field value and create application related record to contact.
if no contact is present, then create new contact record and create a application related record.

We have application id as a external id, which is tagged to application related record. No external id is mapped to Contact.

Wrote some logic, but it is working for insert operation, but it is failing for update the contact record.
Can anyone suggest some workaround? Thanks.

public with sharing class ContactSLMCreateHelper {
    
    public static void createSLM(List<TY_Imports__c> Imports){     
        List<Admission__c> insertSLMList = new List<Admission__c>();
        Set<String> contactIds = new Set<String>();
        Map<String, Contact> contactsToInsert = new Map<String, Contact>();
        Map<String, Contact> contactsToUpdate = new Map<String, Contact>();
        List<Contact> con=[select Id,FirstName,LastName from Contact ];
        // Contact copied form TY import class
        for(TY_Imports__c TY : Imports) 
        {
            for(integer i=0; i < con.size();i++)
            {
                  if (con[i].FirstName ==TY.First_Name__c  && con[i].LastName==TY.Last_or_Family_Name__c) {
         
                     system.debug('updating the record');
                    Contact c = new Contact();
                       if (TY.Last_or_Family_Name__c!= null) {
                     c.LastName = TY.Last_or_Family_Name__c;
                    }     
                    else { 
                     c.LastName='No Last Name';
                         }  
                c.FirstName= TY.First_Name__c;
                c.GU_ID__c= TY.GUID__c;
                c.Ethnicity__c= TY.Ethnicity__c;
                contactsToupdate.put(TY.Applicant_Client_ID__c , c);
                }
               
         
                else{
                    system.debug('creating new record');
                    contact c = new Contact();
                    if (TY.Last_or_Family_Name__c!= null) {
                     c.LastName = TY.Last_or_Family_Name__c;
                    }     
                    else { 
                     c.LastName='No Last Name';
                         }  
                c.FirstName= TY.First_Name__c;
                c.GU_ID__c= TY.GUID__c;
                c.Ethnicity__c= TY.Ethnicity__c;
                contactsToInsert.put(TY.Applicant_Client_ID__c , c);
                    
                }
            }}
         System.debug('Testing for contact.') ;  
        if ( contactsToupdate.values()!= null )
        {
            System.debug('About to update Contact ' + contactsToupdate.values());
            update contactsToupdate.values(); 
            System.debug('AFTER update of contact Records');
        }
          if(contactsToinsert.values()!= null){
              System.debug('About to insert Contact ' + contactsToInsert.values());
             insert contactsToInsert.values(); 
              System.debug('AFTER insert of contact Records');
            }
        RecordType SLMRecordType;
        List<RecordType> SLMRecordTypes = [ select Id, Name, DeveloperName from RecordType where SObjectType = 'Admission__c' ];
        
        if ( SLMRecordTypes != null && SLMRecordTypes .size() > 0 )
        {
            SLMRecordType = SLMRecordTypes [0];        
        }
        else
        {
            SLMRecordType = new RecordType(id='01240000000UcwV');
        }
        
        for(TY_Imports__c TY : Imports) {
            if (TY.Applicant_Client_ID__c != NULL) {
                Admission__c adm = new Admission__c();
        
                adm.Applicant_Client_ID__c = TY.Applicant_Client_ID__c;
                adm.Age_at_Time_of_Enrollment__c = TY.Age_at_Time_of_Enrollment__c;
                adm.RecordTypeId = SLMRecordType.Id;
                adm.TY_Application_Term__c= TY.Application_Term__c;
                adm.TY_Admitted_Date__c= TY.TY_Admitted_Date__c;
                adm.TY_Enrolled_Date__c= TY.TY_Enrolled_Date__c;
                adm.Decision_Date__c = TY.Decision_Date__c;
                adm.Enrollment_Decision__c = TY.Enrollment_Decision__c;
                adm.Months_of_work_NEW__c= TY.Months_of_work_NEW__c;
                if (contactsToInsert.containsKey(TY.Applicant_Client_ID__c)) {
                adm.ContactLookUp__c= contactsToInsert.get(TY.Applicant_Client_ID__c).id;
                }
            insertSLMList.add(adm);
                 }   
            }
        System.debug('Testing for SML.') ;  
        if ( insertSLMList!= null )
        {
           if ( !Test.isRunningTest() )
            {
               System.debug('About to insert SLM. ' + insertSLMList);
               upsert insertSLMList Applicant_Client_ID__c ;  
               System.debug('AFTER insert of SLM Records');
            }
            else
            {
              try
              {
                upsert insertSLMList Applicant_Client_ID__c ; 
               }
              catch(Exception e)
              {
                System.debug(LoggingLevel.ERROR, '---> caught exception Upserting SLMList: ' + e.getMessage() );
               }
             }
           }
        }
    }