• Zach Bratcher
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies
I am currently working on building a custom visual force page that will upsert new contact records. The issue I am not able to get it to update the record. It does create new records and if the email already exists and the user clicks on submit the page just blinks and does nothing. Here is the APEX code I have for the upsert.
 
public class NewAndExistingController {



    public Contact contact { get; private set; }

    
    public NewAndExistingController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        contact = (id == null) ? new Contact() : 
            [SELECT id, firstname, lastname, phone, email, MailingStreet, MailingPostalCode, MailingState, birthdate, TargetX_SRMb__Campus__c, TargetX_SRMb__Program__c, Dual_Enrollment__c, 
            TargetX_SRMb__Gender__c, Attended_College_Previously__c, Attended_TSTC_Previously__c, Reason__c, Preferred_Method_of_Contact__c, Preferred_Name__c, High_School2__c, Previous_College__c
            FROM Contact WHERE Id = :id];
            
    }
  
    public PageReference save() {
        try {
            upsert contact;
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //  After successful Save, navigate to the default view page
        PageReference redirectSuccess = new PageReference('http://google.com');
        redirectSuccess.setRedirect(true);
        return (redirectSuccess);
    }
    
}

 
I currently have a custom field on the Contacts Object called Field Lable: Colleague ID API Name: TargetX_SRMb__Colleague_ID__c that I need when it gets filled in to trigger and copy the data from Colleague ID field and add it to the Field Lable: SRM ETL ID API Name: TargetX_SRMb__SRM_ETL_ID__c on the Application Object
I am currently working on building a custom visual force page that will upsert new contact records. The issue I am not able to get it to update the record. It does create new records and if the email already exists and the user clicks on submit the page just blinks and does nothing. Here is the APEX code I have for the upsert.
 
public class NewAndExistingController {



    public Contact contact { get; private set; }

    
    public NewAndExistingController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        contact = (id == null) ? new Contact() : 
            [SELECT id, firstname, lastname, phone, email, MailingStreet, MailingPostalCode, MailingState, birthdate, TargetX_SRMb__Campus__c, TargetX_SRMb__Program__c, Dual_Enrollment__c, 
            TargetX_SRMb__Gender__c, Attended_College_Previously__c, Attended_TSTC_Previously__c, Reason__c, Preferred_Method_of_Contact__c, Preferred_Name__c, High_School2__c, Previous_College__c
            FROM Contact WHERE Id = :id];
            
    }
  
    public PageReference save() {
        try {
            upsert contact;
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //  After successful Save, navigate to the default view page
        PageReference redirectSuccess = new PageReference('http://google.com');
        redirectSuccess.setRedirect(true);
        return (redirectSuccess);
    }
    
}

 
I currently have a custom field on the Contacts Object called Field Lable: Colleague ID API Name: TargetX_SRMb__Colleague_ID__c that I need when it gets filled in to trigger and copy the data from Colleague ID field and add it to the Field Lable: SRM ETL ID API Name: TargetX_SRMb__SRM_ETL_ID__c on the Application Object