• sam khan 13
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
trigger Avoidduplicateprimarycontact on Contact(before insert , before update){
    Map<ID,Contact> accountIds = new Map<ID,Contact>();
    for(Contact c : Trigger.New){
        accountIds.put(c.AccountId,c);
    }   
    for(Account acc : [Select Id , (Select Id, priority__c from Contacts) From Account Where Id IN :accountIds.keyset()]) 
    { 
        for(Contact con : acc.contacts)
        {
            if(accountIds.get(acc.Id).priority__c == 'Primary')
            {
                if(con.priority__c == 'Primary')
                {
                    con.adderror('There  is already one primary contact exists.');
                } 
            } 
        }}}

User-added image
Hi,
I want to work on below task, Can anyone please help me in that task

Create a visual force page with two page blocks, one showing the existing Accounts and another for inserting new accounts. The inserted account also needs to be dynamically displayed in the existing Account list.

Thanks in Advance.