• Chris Pulliam
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies
<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you for your response.
    </apex:form>
</apex:page>
^ Visualforce page. When someone clicks a link in an alert email I sent them it directs them here, and appends a value in the url based on what link in the alert they click: accepted or rejected. 
 
public class MyCustomVFPage_CTR {
    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public MyCustomVFPage_CTR () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference InitPage() {
        List<Lead> CustomerIssues = [SELECT Id, Status FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!CustomerIssues.IsEmpty()){
            CustomerIssues[0].Status = ResponseCode;
            UPDATE CustomerIssues;
        }
        Return null;
    }
}
^ class takes the value that's passed from the url, and updates the related record.

I don't know how to get code coverage for that class. Do I need to write something to test going to a visualforce page?





 
@isTest 

public class AccRelatedContTest
{    
      static testmethod void updateOpp() {
      
             Account testAccount = new Account();
        
        testAccount.Name='Test Account' ;        
        testAccount.OwnerID = '005d0000003Xjjh';
        testAccount.Website = 'hopethisworks.com';
        testAccount.recordtypeid = '012d0000000PBVJ';
        insert testAccount;
        
        Contact cont = new Contact();
        cont.FirstName='Test';
        cont.LastName='Test';
        cont.Accountid= testAccount.id;
        insert cont;
        
      Opportunity o = new Opportunity(
        Name='Test Opp',
        NextStep = 'Testing',
        Accountid= testAccount.id,
        StageName = 'Prospect',
        Probability=100,
        CloseDate = date.today(),
        RecordTypeid = '012d0000000PDkW');
        insert o;
        
        
    }
}
This is the test class code attempting to provide code coverage for an opportunity create and update trigger. When I run it without the opportunity part it passes fine, but when I include it gives a "Methods defined as TestMethod do not support Web service callouts" error, which is frustrating because I'm not making any Web service callouts (I think?!)

Any help is greatly appreciated. Thanks.
I'm very new to Apex. I tried writing a trigger to help solve an orphan lead problem in our instance, and relate leads to accounts. It looks at all leads in our instance with the same domain, and either attaches it to an account if one exists or creates an account, and attaches the lead.

I'm almost there, but when I brought it into production, and try creating or updating a lead, and I get this nasty error message. I pasted the error and code below. Does anyone know how to get through this?

Error:attachLeadToAccount1: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Trigger.attachLeadToAccount1: line 11, column 1 No record updated

Trigger:
trigger attachLeadToAccount1 on Lead (before Insert, before update) {

  // Get Lead Ids from all of the triggered Tasks
  set<string> leadIds = new set<string>();
  for(Lead myTask :trigger.new) {
    leadIds.add(myTask.domain__c);
  }

  // Get Leads and build a map of <LeadId,Lead_Accounts__c>
  map<string,id> mLeadAccountIds = new map<string,id>();
  list<Lead> leads = [SELECT domain__c, Lead_Accounts__c FROM Lead WHERE domain__c IN :leadIds];
  for(Lead l :leads) {
    mLeadAccountIds.put(l.domain__c,l.Lead_Accounts__c);
  }

  // Update triggered tasks with Account Id
  for(Lead t :trigger.new) {
    if(mLeadAccountIds.containsKey(t.domain__c) && t.email != null && t.Lead_Accounts__c == null && t.domain__c != 'outlook.com' && t.domain__c != 'gmail.com' && t.domain__c != 'yahoo.com' && t.domain__c != 'hotmail.com' && t.domain__c != 'googlemail.com' && t.domain__c != 'aol.com' && t.domain__c != 'mail.com' && t.domain__c != 'mail2web.com' && t.domain__c != 'mailinator.com' && t.domain__c != '10minutemail.com' && t.domain__c != '123vn.com') {
      t.Lead_Accounts__c = mLeadAccountIds.get(t.domain__c);
      t.Lead_Account_Attachment_Audit_Key__c = 'Attached';
          }
     if(t.email != null && t.Lead_Accounts__c == null && t.domain__c != 'outlook.com' && t.domain__c != 'gmail.com' && t.domain__c != 'yahoo.com' && t.domain__c != 'hotmail.com' && t.domain__c != 'googlemail.com' && t.domain__c != 'aol.com' && t.domain__c != 'mail.com' && t.domain__c != 'mail2web.com' && t.domain__c != 'mailinator.com' && t.domain__c != '10minutemail.com' && t.domain__c != '123vn.com') {
     Account a = new account();
     a.Name = t.company+' ('+t.domain__c+')';
     a.Website = t.domain__c;
     a.Created_From_Lead_Account_Attach_Trigger__c = 'Created from Trigger';
     insert a;
     
     t.Lead_Accounts__c = a.id;
    
  }
  }

}
Class:
@isTest
public class attachLeadToAccount1_Test
{    
      public static testmethod void testinsert()
      {

Account account= new account();
account.Name = 'United States Government';
account.OwnerID = '005d0000003Xjjh';
account.Website = 'hopethisworks.com';
account.recordtypeid = '012d0000000PBVJ';
insert account;

Lead lead= new lead();
lead.Firstname = 'Barack';
lead.Lastname = 'Obama';
lead.email ='barackyoursoxoff@usgov.com';
lead.company = 'United States Government';
lead.Lead_Accounts__c = [Select id from Account where Name = 'United States Government' limit 1].id;
insert lead;
            
Lead lead1= new lead();
lead1.Firstname = 'Michelle';
lead1.Lastname = 'Obama';
lead1.email ='baracksboss@usgov.com';
lead1.company = 'United States Government';
insert lead1;   

Lead lead2= new lead();
lead2.Firstname = 'Malaka';
lead2.Lastname = 'Obama';
lead2.email ='barackyoursoxoff1@gmail.com';
lead2.company = 'United States Government';
insert lead2;

Lead lead3= new lead();
lead3.Firstname = 'Mama';
lead3.Lastname = 'Obama';
lead3.email ='barackyoursoxoff1@newaccounttest.com';
lead3.company = 'New Account Test';
insert lead3;               

}
}

 
#stumped

Trigger
trigger attachLeadInTaskToAccount on Task (before update) {
  // Get Lead Ids from all of the triggered Tasks
  set<id> leadIds = new set<id>();
  for(Task myTask :trigger.new) {
    leadIds.add(myTask.whoId);
  }

  // Get Leads and build a map of <LeadId,Lead_Accounts__c>
  map<id,id> mLeadAccountIds = new map<id,id>();
  list<Lead> leads = [SELECT id, Lead_Accounts__c FROM Lead WHERE Id IN :leadIds];
  for(Lead l :leads) {
    mLeadAccountIds.put(l.id,l.Lead_Accounts__c);
  }

  // Update triggered tasks with Account Id
  for(Task t :trigger.new) {
    if(mLeadAccountIds.containsKey(t.whoId)) {
      t.whatId = mLeadAccountIds.get(t.whoId);
          }
  }

}

Test Class
@isTest
public class attachLeadInTaskToAccount_Test
{
      public static testmethod void testinsert()
      {
            
list<Lead> leads = [SELECT id, Lead_Accounts__c FROM Lead WHERE Lead_Accounts__c !=null AND Lead_Accounts__r.Name = 'test'];

if(leads.size() > 0) {

String lead1 = leads[1].id;
String lead2 = leads[2].id;
String lead3 = leads[3].id;

Task task= new task();
task.Subject='Message Sent 1';
task.status='Completed';
task.Whoid= lead1;
insert task;

Task task1= new task();
task1.Subject='Call';
task1.status='Completed';
task1.Whoid= lead2;
insert task1;

Task task2= new task();
task2.Subject='Message Sent 3';
task2.status='Completed';
task2.Whoid= lead3;
insert task2;

task.Subject = 'Closed';
update(task);

task1.Subject = 'Closed';
update(task1);

task2.Subject = 'Closed';
update(task2);

}
        }

}

 
Hi there.
Working on my first trigger. The trigger works, and I can get 80% code coverage with the test class below. However, when I try to bring it into production it fails.
trigger attachToAccount on Task (before update) {
  // Get Lead Ids from all of the triggered Tasks
  set<id> leadIds = new set<id>();
  for(Task myTask :trigger.new) {
    leadIds.add(myTask.whoId);
  }

  // Get Leads and build a map of <LeadId,Lead_Accounts__c>
  map<id,id> mLeadAccountIds = new map<id,id>();
  list<Lead> leads = [SELECT id, Lead_Accounts__c FROM Lead WHERE Id IN :leadIds];
  for(Lead l :leads) {
    mLeadAccountIds.put(l.id,l.Lead_Accounts__c);
  }

  // Update triggered tasks with Account Id
  for(Task t :trigger.new) {
    if(mLeadAccountIds.containsKey(t.whoId)) {
      t.whatId = mLeadAccountIds.get(t.whoId);
    }
  }

}



My test class gives me 80% code coverage, but when I send everything through a change set the class fails with an INVALID_CROSS_REFERENCE_KEY Exception. My hunch is that this is because the lead IDs I use in WhoId are to leads that exist in sandbox, but not production. 

How would I write this in a way that it works when I deploy?
@isTest
public class ActivityCountTest_Test
{
      public static testmethod void testinsert()
      {

Task task= new task();
task.Subject='Message Sent 1';
task.status='Completed';
task.Whoid='00Q55000001r6Bv';
insert task;

Task task1= new task();
task1.Subject='Call';
task1.status='Completed';
task1.Whoid='00Q55000001r6C0';
insert task1;

Task task2= new task();
task2.Subject='Message Sent 3';
task2.status='Completed';
task2.Whoid='00Q55000001r6C0';
insert task2;

task.Subject = 'Closed';
update(task);

task1.Subject = 'Closed';
update(task1);

task2.Subject = 'Closed';
update(task2);

        }

}

 
I am very new to triggers. I made one that works in my sandbox, but from what I read I need to bulkify it so it doesn't fail when we mass update tasks. I know I'm supposed to pull SOQL out of the for loop. Beyond that I'm stuck.
 
trigger attachToAccount on Task (before update) {
for (Task myTask: Trigger.new)
  if (myTask.Subject != null){
   List<Lead> dupes = [SELECT Id, Lead_Accounts__c FROM Lead WHERE Id = :myTask.Whoid];
         if (dupes.size() > 0) {
                 myTask.WhatId = dupes[0].Lead_Accounts__c;
   } else {
           myTask.Subject = null;
}
}
}

 
Hi, I orginally directed this question at Salesforce, and stumped the support specialist, who directed me here.

My company uses google to run our company email through. We set up our google account as an Auth. Provider, so users can click a button to log in on our My Domain page. The first time, it connects the person's work email account to salesforce. Each time after, they press the button when logged into their email, and it logs them in.

This works for most users. However, for at least one user, it fails every time. 

"There was a problem with your authentication attempt. Please try again. If you continue to encounter problems, contact your administrator."

I have confirmed that Salesforce does connect to his email account because I can see it in the gmail settings. I have confirmed the email is identical to what we have in sfdc for him. We have tried uninstalling, reinstalling. We have tried logging out of email, and connecting again.

I'm not sure what's going on here. Do any of you have light to shed?

Thanks!

 
<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you for your response.
    </apex:form>
</apex:page>
^ Visualforce page. When someone clicks a link in an alert email I sent them it directs them here, and appends a value in the url based on what link in the alert they click: accepted or rejected. 
 
public class MyCustomVFPage_CTR {
    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public MyCustomVFPage_CTR () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference InitPage() {
        List<Lead> CustomerIssues = [SELECT Id, Status FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!CustomerIssues.IsEmpty()){
            CustomerIssues[0].Status = ResponseCode;
            UPDATE CustomerIssues;
        }
        Return null;
    }
}
^ class takes the value that's passed from the url, and updates the related record.

I don't know how to get code coverage for that class. Do I need to write something to test going to a visualforce page?





 
<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you for your response.
    </apex:form>
</apex:page>
^ Visualforce page. When someone clicks a link in an alert email I sent them it directs them here, and appends a value in the url based on what link in the alert they click: accepted or rejected. 
 
public class MyCustomVFPage_CTR {
    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public MyCustomVFPage_CTR () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference InitPage() {
        List<Lead> CustomerIssues = [SELECT Id, Status FROM Lead WHERE Id=:ObjectId LIMIT 1];
        if(!CustomerIssues.IsEmpty()){
            CustomerIssues[0].Status = ResponseCode;
            UPDATE CustomerIssues;
        }
        Return null;
    }
}
^ class takes the value that's passed from the url, and updates the related record.

I don't know how to get code coverage for that class. Do I need to write something to test going to a visualforce page?





 
@isTest 

public class AccRelatedContTest
{    
      static testmethod void updateOpp() {
      
             Account testAccount = new Account();
        
        testAccount.Name='Test Account' ;        
        testAccount.OwnerID = '005d0000003Xjjh';
        testAccount.Website = 'hopethisworks.com';
        testAccount.recordtypeid = '012d0000000PBVJ';
        insert testAccount;
        
        Contact cont = new Contact();
        cont.FirstName='Test';
        cont.LastName='Test';
        cont.Accountid= testAccount.id;
        insert cont;
        
      Opportunity o = new Opportunity(
        Name='Test Opp',
        NextStep = 'Testing',
        Accountid= testAccount.id,
        StageName = 'Prospect',
        Probability=100,
        CloseDate = date.today(),
        RecordTypeid = '012d0000000PDkW');
        insert o;
        
        
    }
}
This is the test class code attempting to provide code coverage for an opportunity create and update trigger. When I run it without the opportunity part it passes fine, but when I include it gives a "Methods defined as TestMethod do not support Web service callouts" error, which is frustrating because I'm not making any Web service callouts (I think?!)

Any help is greatly appreciated. Thanks.
Hi there.
Working on my first trigger. The trigger works, and I can get 80% code coverage with the test class below. However, when I try to bring it into production it fails.
trigger attachToAccount on Task (before update) {
  // Get Lead Ids from all of the triggered Tasks
  set<id> leadIds = new set<id>();
  for(Task myTask :trigger.new) {
    leadIds.add(myTask.whoId);
  }

  // Get Leads and build a map of <LeadId,Lead_Accounts__c>
  map<id,id> mLeadAccountIds = new map<id,id>();
  list<Lead> leads = [SELECT id, Lead_Accounts__c FROM Lead WHERE Id IN :leadIds];
  for(Lead l :leads) {
    mLeadAccountIds.put(l.id,l.Lead_Accounts__c);
  }

  // Update triggered tasks with Account Id
  for(Task t :trigger.new) {
    if(mLeadAccountIds.containsKey(t.whoId)) {
      t.whatId = mLeadAccountIds.get(t.whoId);
    }
  }

}



My test class gives me 80% code coverage, but when I send everything through a change set the class fails with an INVALID_CROSS_REFERENCE_KEY Exception. My hunch is that this is because the lead IDs I use in WhoId are to leads that exist in sandbox, but not production. 

How would I write this in a way that it works when I deploy?
@isTest
public class ActivityCountTest_Test
{
      public static testmethod void testinsert()
      {

Task task= new task();
task.Subject='Message Sent 1';
task.status='Completed';
task.Whoid='00Q55000001r6Bv';
insert task;

Task task1= new task();
task1.Subject='Call';
task1.status='Completed';
task1.Whoid='00Q55000001r6C0';
insert task1;

Task task2= new task();
task2.Subject='Message Sent 3';
task2.status='Completed';
task2.Whoid='00Q55000001r6C0';
insert task2;

task.Subject = 'Closed';
update(task);

task1.Subject = 'Closed';
update(task1);

task2.Subject = 'Closed';
update(task2);

        }

}

 
I am very new to triggers. I made one that works in my sandbox, but from what I read I need to bulkify it so it doesn't fail when we mass update tasks. I know I'm supposed to pull SOQL out of the for loop. Beyond that I'm stuck.
 
trigger attachToAccount on Task (before update) {
for (Task myTask: Trigger.new)
  if (myTask.Subject != null){
   List<Lead> dupes = [SELECT Id, Lead_Accounts__c FROM Lead WHERE Id = :myTask.Whoid];
         if (dupes.size() > 0) {
                 myTask.WhatId = dupes[0].Lead_Accounts__c;
   } else {
           myTask.Subject = null;
}
}
}