• Shreya Jain
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
I have a custom object Staging__c with fields Firstname__c, Lastname__c, PostalCode__c . Now, I have to check or search for existing contacts with matching  FirstName,Lastname,PostalCode. If contact not found , then we have to create a contact. This have to be done in Batch Class.
I override the account "edit" button. I made visualforce page and apex class for this. In visualforce page, there are contacts that are related to account and each contact have an edit and delete button. When i click on "edit" button it opens a contact edit page(Standard) and save that record.
My requirement is -
when i edit a record and save it. After saving it goes to Parent page(Visualforce page- Account edit page).

Visualforce Page
<apex:page standardController="Account" extensions="AccountEditButtonPage" tabStyle="Account">
    <apex:sectionHeader title="Account Edit" subtitle="New Account" />
    <apex:form id="RID">
        <apex:pageblock title="Account Edit"> 
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!Save}"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>                       
            </apex:pageBlockButtons>                       
            <apex:pageBlockSection title="Account Information" collapsible="false" columns="2">
                <apex:inputField value="{!Account.ownerId}" />
                <apex:inputField value="{!Account.Rating}" />
                <apex:inputField value="{!Account.name}" />
                <apex:inputField value="{!Account.Phone}" />
                <apex:inputField value="{!Account.ParentId}" />
                <apex:inputField value="{!Account.fax}" />
                <apex:inputField value="{!Account.AccountNumber}" />
                <apex:inputField value="{!Account.Website}" />
                <apex:inputField value="{!Account.Site}" />
                <apex:inputField value="{!Account.TickerSymbol}" />
                <apex:inputField value="{!Account.type}" />
                <apex:inputField value="{!Account.ownership}" />
                <apex:inputField value="{!Account.Industry}" />
                <apex:inputField value="{!Account.NumberOfEmployees}" />
                <apex:inputField value="{!Account.AnnualRevenue}" />
                <apex:inputField value="{!Account.Sic}" />
                <apex:inputField value="{!Account.Contact__c}" />
                <apex:inputField value="{!Account.site}" />
                </apex:pageBlockSection>
                
                <apex:pageBlockSection title="Address Information" collapsible="false" columns="2">
                <apex:inputField value="{!Account.BillingStreet}" />
                <apex:inputField value="{!Account.ShippingStreet}" />
                <apex:inputField value="{!Account.BillingCity}" />
                <apex:inputField value="{!Account.ShippingCity}" />
                <apex:inputField value="{!Account.BillingState}" />
                <apex:inputField value="{!Account.ShippingState}" />
                <apex:inputField value="{!Account.BillingPostalCode}" />
                <apex:inputField value="{!Account.ShippingPostalCode}" />
                <apex:inputField value="{!Account.BillingCountry}" />
                <apex:inputField value="{!Account.ShippingCountry}" />
            </apex:pageBlockSection>            
            <apex:pageBlockSection title="Additional Information" collapsible="false" columns="2">
                <apex:inputField value="{!Account.CustomerPriority__c}" />
                <apex:inputField value="{!Account.SLA__c}" />
                <apex:inputField value="{!Account.SLAExpirationDate__c}" />
                <apex:inputField value="{!Account.SLASerialNumber__c}" />
                <apex:inputField value="{!Account.NumberofLocations__c}" />
                <apex:inputField value="{!Account.UpsellOpportunity__c}" />
                <apex:inputField value="{!Account.Active__c}" />
                <apex:inputField value="{!Account.AccountSource}" />
                </apex:pageBlockSection>
                
                <apex:pageBlockSection title="Description Information" collapsible="false">
                <apex:inputField value="{!Account.Description}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Contacts">
            <apex:pageBlockTable value="{!conList}" var="con">
                <apex:column >
                <apex:commandButton value="Edit" action="{!editCont}" reRender="RID">
                <apex:param value="{!con.id}" name="editId" assignTo="{!editId}"/>
                </apex:commandButton>
                <apex:commandButton value="Delete" action="{!delContact}" reRender="RID">
                    <apex:param value="{!con.id}" name="contactId" assignTo="{!contactId}"/>
                </apex:commandButton>
                </apex:column>
                <apex:column value="{!con.Name}"/>
                <apex:column value="{!con.Email}"/>
                <apex:column value="{!con.Phone}"/>                
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class
public class AccountEditButtonPage {        
    public String accId {get;set;}       
    public List<Contact> conList{get;set;}
    public String contactId{get;set;}  
    public String editId{get;set;}
    public AccountEditButtonPage(ApexPages.StandardController controller) {
        accId  = ApexPages.CurrentPage().getparameters().get('id');
        conList = [select id,Name,email,Phone from contact where AccountId =: accId];
        system.debug('--8--' +conList);
    }
    public pageReference delContact(){        
        system.debug('--12--'+contactId);
        Contact conRecord = [select id from contact where id= :contactId];
        Delete conRecord;
        PageReference retURL = new PageReference('/apex/AccEditButtonOverridePage?id='+accId);
        retURL.setRedirect(true);
        return retURL;
    }
    public PageReference editCont(){
        system.debug('--10--'+editId);
         PageReference editURL = new PageReference('/'+editId+'/e');     
        editURL.setRedirect(true);
        return editURL;
        }  
    
}


 
I have a custom object Staging__c with fields Firstname__c, Lastname__c, PostalCode__c . Now, I have to check or search for existing contacts with matching  FirstName,Lastname,PostalCode. If contact not found , then we have to create a contact. This have to be done in Batch Class.