• cnovo
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
We have a trigger to look for duplicate contacts that our developer created before he left the company. It has been working fine, but I was hoping to update it to not take into account contacts that are created by a partner user. So if one of our users is trying to insert a contact that has the same email address as a contact for an Account that is owned by one of our partners...it won't give our user a duplicate error. I was hoping someone might be able to help me out with the code that is needed to accomplish this. This is what our trigger looks like today. Any help would be greatly appreciated.

trigger ContactBefore on Contact (before insert, before update) {
    /* Prevent duplicate contacts 
    *  duplicate qualifier fields: last name, email
    *  ignor duplicate check if the ignoreDuplicatePrevention field equels true
    */
    
    ID Userid;
    Map<Id, User> owners;
    Set<Id> ownerIdSet = new Set<Id>();
    Map<String, Contact> contactMap = new Map<String, Contact>();
    Set<String> emailSet = new Set<String>();
    String compositeKey = null;
    
    Userid=userinfo.getuserid();
    User u=new User(ID=Userid);
    system.debug('*** UserID= '+Userid);
    system.debug('*** isInsert= ' + trigger.isInsert);
    system.debug('*** isUpdate= ' + trigger.isUpdate);
    
    for(Contact c : trigger.new) {
        ownerIdSet.add(c.OwnerId);  
    }
    owners = new Map<Id, User>([SELECT UserType FROM User WHERE Id IN :ownerIdSet]);
        
    for(Contact c : system.trigger.new) {
        if(!c.Ignore_Duplicate_Prevention__c && ((trigger.isInsert && Userinfo.getUserType() == 'Standard') || (trigger.isUpdate && owners.get(c.OwnerId).UserType == 'Standard')) && !Utilities.isNullOrEmpty(c.Email)) {
            compositeKey = c.Email;
            // Make sure we don't treat an email address that
            // isn't changing during an update as a duplicate.
            if(trigger.isInsert || c.Email != trigger.oldMap.get(c.Id).Email) {
            
                // Make sure another new contact isn't also a duplicate
                if(contactMap.containsKey(compositeKey)) {
                if(u.Isportalenabled==false){
                    c.Email.addError('Another new contact has the same email address.');
                    contactMap.get(compositeKey).Email.addError('Another new contact has the same email address.');
                    }
                } else {
                    contactMap.put(compositeKey, c);
                    emailSet.add(c.Email);
                }
            }
        }
    }
    
    if(!emailSet.isEmpty()) {
        for(Contact c : [SELECT Email FROM Contact WHERE Email IN :emailSet]) {
            compositeKey = c.Email;
            if(contactMap.containsKey(compositeKey)) {
                contactMap.get(compositeKey).Email.addError('A contact with this email address already exists.');
            }
        }
    }
    
    
    
}
  • November 12, 2014
  • Like
  • 0

I have a trigger I created based on code the developer on out team wrote prior to leaving the company. It seems pretty simple, but I don't know how to write a test class for the trigger so I'm unable to deploy it. Any help would be greatlyappreciated.

 

trigger SupportCaseAfter on Support_Case__c (after insert, after update) {
ChatterAutoFollow.subscribeAutoFollowers(trigger.newMap, trigger.oldMap);
}

  • December 05, 2013
  • Like
  • 0

I was trying to add a related list to a VF page to appear under an iframe.

 

Here is my code.

 

<apex:page standardController="Custom_object__c" cache="false">
<chatter:feed entityId="{!Custom_object__c.id}"/>
<apex:detail relatedList="false"/>
<apex:iframe src="http://url.here.com/extranet/CustomerPortalOrderStatus.asp?OrderID={!Custom_object__c.ID}" scrolling="True" id="theIframe"/>
<apex:relatedList list="openActivities"/>
</apex:page>

 

Everything worked fine in Chrome and Safari on a Mac, but not in IE.

 

Users in IE were getting a "Unable to load Visualforce page" error.

 

What might I be doing wrong?

  • July 16, 2013
  • Like
  • 0

We have custom object the is a the Detail of a Master-Detail with Accounts. We are trying to override the "New" button so that the Account field is pre-populated. I'm sure this is possible with a VF page, but not quite sure how to do it. Can anyone help?

  • March 27, 2013
  • Like
  • 0

I have a trigger I created based on code the developer on out team wrote prior to leaving the company. It seems pretty simple, but I don't know how to write a test class for the trigger so I'm unable to deploy it. Any help would be greatlyappreciated.

 

trigger SupportCaseAfter on Support_Case__c (after insert, after update) {
ChatterAutoFollow.subscribeAutoFollowers(trigger.newMap, trigger.oldMap);
}

  • December 05, 2013
  • Like
  • 0