• Jessica Puckett
  • NEWBIE
  • 20 Points
  • Member since 2015
  • Marketing Specialist
  • Settlers Life Insurance Company

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Hello everyone,
We have a Visualforce page calling an Apex Class which currently obtains the record Id from the URL.  We're attempting to implement Console and this process no longer works in Console View.  I'm trying to understand how to replace the referheader with the getEnclosingPrimaryTabObjectId() function for Console, but I keep coming up short.  Any advice would be appreciated!  Here's the existing code:
public with sharing class TaskSidebarExtension {
  public Task tsk {get;set;}
  public String refer {get;set;}
  public Boolean valid {get;set;}
  public String parentId {get;set;}
  public String recordName {get;set;}
  public String phoneNumber {get;set;}
  public string redirectUrl {get;set;}
  
  public TaskSidebarExtension(ApexPages.standardController ctl) {
    this.tsk = (Task)ctl.getRecord();
    
  }
  
  public void findRecord() {
    valid = true;
    try {      
      //check the referer header (send via the iFrame) and extract the record id
      String referHeader = ApexPages.currentPage().getHeaders().get('referer');
      if (referHeader != null) {
        refer = referHeader;
      }
      
      if (refer != null) {
        Integer startPos = refer.lastIndexOf('/')+1;
        Integer endPos = refer.indexOf('?');
        if (endPos < 0) endPos = refer.length();
        
        parentId = refer.substring(startPos,endPos);
      }
      
    
I am attempting to learn Apex and last week successfully deployed my first (and admittedly rudimentary) Apex trigger to production.  Everything was going great until I attempted to update some of my Contact records via DataLoader.  I received a System.LimitException: Apex CPU time limit exceeded error.  I was able to successfully break my .csv file into 200-part pieces and upload, but I know there must be a better way.  As I understand it, the loops in my trigger are the cause, but I'm not sure how to improve the code to solve this.  My code is below and suggestions are greatly appreciated!

trigger contactDupCheck2 on Contact (before insert, before update, before delete) {
    set<string> emailSet = new set<string>();
    List<contact> contactList = new list<contact>();
    
    for(contact c : trigger.new){
        if(c.email!=null || c.email!=''){
            emailSet.add(c.email);
            contactList.add(c);
        }
    }
    List<Contact> listExistingContact = [select Id, email, LastName from Contact where email in: emailSet and id not in : trigger.new];
    for(contact currCon: contactList ){
    currcon.duplicate_email__c=false;
        for(contact exiscon : listExistingContact ){
            if(currcon.email==exiscon.email){
                currcon.duplicate_email__c=true;
            } else {
            currcon.duplicate_email__c=false;
            }
            if(currcon.email==null || currcon.email==''){
            currcon.duplicate_email__c=false;
            }
           
        }
    }
}
Hello all,
I'm working on an Apex trigger and am running into an issue I'm not sure how to resolve.  (I'm still quite new to Apex.)  I'm receiving the following problem on lines 2 and 3:  "Invalid bind expression type of Contact for column of type String"  Suggestions are greatly appreciated! 
My trigger code is below:

trigger EmailDuplicate on Contact (before insert, before update, before delete) {
    List<Contact> emaillist = [SELECT id,email FROM Contact WHERE Email!=null AND Email IN :trigger.new];
    List<Contact> existingcontact = [SELECT id, email,lastname FROM Contact WHERE email IN :emaillist AND id NOT IN :trigger.new];
    for(Contact current : emaillist){
        for(Contact existing : existingcontact){
            if(current.Email==existing.Email){
                current.duplicate_email__c=true;
            }
                else if (current.Email!=existing.Email){
                    current.duplicate_email__c=false;
                    
                    update emaillist;
                }
            }
        }
    }

 
Hello community!  I'm hoping you can give me some direction here...
We have (and allow) multiple Contact records to have the same email address in our Salesforce org.  Our Contacts are our independent agents and often, multiple agents within an agency share the same email address.

I want to find a way for Salesforce to evaluate all the Email values on our Contact records, and flag a (custom field) checkbox if the email is a duplicate. I've been unable to find a way to do this via a Workflow Rule.  Can it be done via an Apex trigger?  I don't have any experience with triggers, so any advice/guidance would be helpful!

Thank you!
Hello everyone,
We have a Visualforce page calling an Apex Class which currently obtains the record Id from the URL.  We're attempting to implement Console and this process no longer works in Console View.  I'm trying to understand how to replace the referheader with the getEnclosingPrimaryTabObjectId() function for Console, but I keep coming up short.  Any advice would be appreciated!  Here's the existing code:
public with sharing class TaskSidebarExtension {
  public Task tsk {get;set;}
  public String refer {get;set;}
  public Boolean valid {get;set;}
  public String parentId {get;set;}
  public String recordName {get;set;}
  public String phoneNumber {get;set;}
  public string redirectUrl {get;set;}
  
  public TaskSidebarExtension(ApexPages.standardController ctl) {
    this.tsk = (Task)ctl.getRecord();
    
  }
  
  public void findRecord() {
    valid = true;
    try {      
      //check the referer header (send via the iFrame) and extract the record id
      String referHeader = ApexPages.currentPage().getHeaders().get('referer');
      if (referHeader != null) {
        refer = referHeader;
      }
      
      if (refer != null) {
        Integer startPos = refer.lastIndexOf('/')+1;
        Integer endPos = refer.indexOf('?');
        if (endPos < 0) endPos = refer.length();
        
        parentId = refer.substring(startPos,endPos);
      }
      
    
I am attempting to learn Apex and last week successfully deployed my first (and admittedly rudimentary) Apex trigger to production.  Everything was going great until I attempted to update some of my Contact records via DataLoader.  I received a System.LimitException: Apex CPU time limit exceeded error.  I was able to successfully break my .csv file into 200-part pieces and upload, but I know there must be a better way.  As I understand it, the loops in my trigger are the cause, but I'm not sure how to improve the code to solve this.  My code is below and suggestions are greatly appreciated!

trigger contactDupCheck2 on Contact (before insert, before update, before delete) {
    set<string> emailSet = new set<string>();
    List<contact> contactList = new list<contact>();
    
    for(contact c : trigger.new){
        if(c.email!=null || c.email!=''){
            emailSet.add(c.email);
            contactList.add(c);
        }
    }
    List<Contact> listExistingContact = [select Id, email, LastName from Contact where email in: emailSet and id not in : trigger.new];
    for(contact currCon: contactList ){
    currcon.duplicate_email__c=false;
        for(contact exiscon : listExistingContact ){
            if(currcon.email==exiscon.email){
                currcon.duplicate_email__c=true;
            } else {
            currcon.duplicate_email__c=false;
            }
            if(currcon.email==null || currcon.email==''){
            currcon.duplicate_email__c=false;
            }
           
        }
    }
}
Hello community!  I'm hoping you can give me some direction here...
We have (and allow) multiple Contact records to have the same email address in our Salesforce org.  Our Contacts are our independent agents and often, multiple agents within an agency share the same email address.

I want to find a way for Salesforce to evaluate all the Email values on our Contact records, and flag a (custom field) checkbox if the email is a duplicate. I've been unable to find a way to do this via a Workflow Rule.  Can it be done via an Apex trigger?  I don't have any experience with triggers, so any advice/guidance would be helpful!

Thank you!