• Bill Block
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi all, i'm still learning some ins and outs of VF/Apex and ran into a rather weird problem i'm hoping someone could help me figure out. This might be more of an apex question.

I'm working on a set of VF pages that displays all related task/event information within a table. Right now i'm just working on a VF page for the Opportunity. 

I was able to successfully get this information queried onto the table/VF page with it only showing only the current records related tasks/events... (and not other records) but then I went to clone the VF page I had created and suddenly the VF page stopped showing queried results for the Opportunity record I had clicked on.

The only way I've been able to get this information to re-populate on the table was to go into the class extension I wrote and remove the WHERE clause (where it's supposed to be pulling the recordID of the opportunity)... however this isn't ideal because it then causes the VF page to display every task/event instead of those pertaining to just the Opportunity record I have selected. 

I definitely think it's got something to do with the way i'm trying to query the record ID but i'm not 100% sure because it seemed like it was working just fine up until I tried cloning the VF page.

Here's the VF Page:
 
<apex:page standardController="Opportunity" lightningStylesheets="true" extensions="CombinedActivitiesSortingExtension">
<apex:form >
<apex:pageBlock title="Task History">
<apex:pageBlockTable value="{!taskinfo}" var="task">
<apex:column value="{!task.activitydate}"/>
<apex:column value="{!task.subject}"/>
<apex:column value="{!task.description}"/>
<apex:column value="{!task.status}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Event History">
<apex:pageblockTable value="{!eventinfo}" var="event">
<apex:column value="{!event.activitydate}"/>
<apex:column value="{!event.subject}"/>
<apex:column value="{!event.description}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

And heres the extension I wrote 
 
public with sharing class CombinedActivitiesSortingExtension {
    
    Id oppID;
    private final ID taskid;
    Public List<Task> taskinfo {get;set;}
    Public List<Event> eventinfo {get;set;}
    
    
    
    Public CombinedActivitiesSortingExtension(ApexPages.StandardController stdController) {
        
        oppID = stdController.getId();
        taskid = stdController.getId();
        
        
        taskinfo =   [SELECT ActivityDate, Subject, Description, Status
                      FROM Task
                      WHERE Id= :oppID
                      ORDER BY ActivityDate desc];
        
        eventinfo = [SELECT ActivityDate, Subject, Description
                     FROM Event
                     WHERE Id= :oppID
                     ORDER BY ActivityDate desc];
                     
                       
                     
      
            
   
    }


}

Any help would be super appreciated.
Thank you!







 
Hey all!

With some help I wrote this custom trigger that allows our reps to list some additional contacts and their information on Lead records that then transform into Contact records on lead convert.
 
trigger CreateMoreLeadContacts on Lead (after update) {

list < Contact > listContacts = new List < Contact>();

for(Lead objLead : trigger.new) {

if(objlead.IsConverted && !trigger.oldMap.get(objLead.Id).IsConverted) {

Contact c1=New Contact(
LastName=objLead.Secondary_Lead_Contact_Name__c,
Phone=objLead.Secondary_Lead_Phone__c,
Email=objLead.Secondary_Lead_Email__c);

c1.AccountId = objLead.ConvertedAccountId;
listContacts.add(c1);

Contact c2=New Contact(
LastName=objLead.Tertiary_Lead_Contact_Name__c,
Phone=objLead.Tertiary_Lead_Phone__c,
Email=objLead.Tertiary_Lead_Email__c);

c2.AccountId = objLead.ConvertedAccountId;
listContacts.add(c2);

     }
        
    }
    
    if ( listContacts.size() > 0 )
        insert listContacts;

}
The trigger works just fine and as expected... however, i've now indentified an issue when trying to convert a Lead when no data is present in both "Secondary Contact Lead Name" & "Tertiary Contact Lead Name".

Only way to get around this with the current trigger is to list dummy Contact name data in the custom lead fields before the Lead gets converted.

What would be the best way to encapsulate the trigger so that it doesn't fire when names aren't listed / just when one additional contact is listed? 



 
Hey all,

I'm hoping someone could help me identify what's wrong with this trigger I wrote. To preface, i'm very new to the Apex development/coding side of SF (only my 2nd week doing this!).

Several agents in the company I work for want to have a way to list up to two additional points of contact on their Lead records that then convert over into Contact records when the Lead is converted. After a week or so of digging into this and searching I feel like i'm close to a solution (but not quite)

Here is the trigger as I have it right now; 0% code coverage currently (it was at one point 77% before I updated the test unit to accompany it)
 
trigger MoreContacts_Trigger on Lead (after update) {

List<Lead> newLeads = trigger.new;
Map<Id, Lead> mOldLeads = trigger.oldMap;
Lead oldLead;

Set<Id> convertedAccountIds = new Set<Id>();
Set<Id> convertedContactIds = new Set<Id>();

for (Lead l : newLeads) {

    if (l.convertedAccountId != null) {
        convertedAccountIds.add(l.convertedAccountId);
    }

    if (l.convertedContactId != null) {
        convertedContactIds.add(l.convertedContactId);
    }
    }

    Account accounts =
    [SELECT Id, Name
     FROM Account
     WHERE Id IN : convertedAccountIds];

for(Lead l : Trigger.New){
If(l.IsConverted){


Contact c1=New Contact(
LastName=l.Secondary_Lead_Contact_Name__c,
Phone=l.Secondary_Lead_Phone__c,
Email=l.Secondary_Lead_Email__c, 
AccountId=accounts.id);

insert c1;

Contact c2=New Contact(
LastName=l.Tertiary_Lead_Contact_Name__c,
Phone=l.Tertiary_Lead_Phone__c,
Email=l.Tertiary_Lead_Email__c, 
AccountId=accounts.id);

insert c2;

}}}

And here is the class (100% code coverage with some help from another developer, was 0% before).
@isTest

public class MoreContacts_TriggerClass{
static testmethod void MoreContacts_TriggerClass(){

Lead Lead = new Lead(
LastName='Test',
Company='TestCompany',
Email='test@test.com',
Phone='9996663333'

);

insert Lead;

Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('Qualified');

Database.LeadConvertResult lcr = Database.convertLead(lc, false);

}
}

I'm not sure where to go from here but I want to figure out whats wrong, hoping somone might be able to help me pin-point the error. Thanks in advance!
Hi all, i'm still learning some ins and outs of VF/Apex and ran into a rather weird problem i'm hoping someone could help me figure out. This might be more of an apex question.

I'm working on a set of VF pages that displays all related task/event information within a table. Right now i'm just working on a VF page for the Opportunity. 

I was able to successfully get this information queried onto the table/VF page with it only showing only the current records related tasks/events... (and not other records) but then I went to clone the VF page I had created and suddenly the VF page stopped showing queried results for the Opportunity record I had clicked on.

The only way I've been able to get this information to re-populate on the table was to go into the class extension I wrote and remove the WHERE clause (where it's supposed to be pulling the recordID of the opportunity)... however this isn't ideal because it then causes the VF page to display every task/event instead of those pertaining to just the Opportunity record I have selected. 

I definitely think it's got something to do with the way i'm trying to query the record ID but i'm not 100% sure because it seemed like it was working just fine up until I tried cloning the VF page.

Here's the VF Page:
 
<apex:page standardController="Opportunity" lightningStylesheets="true" extensions="CombinedActivitiesSortingExtension">
<apex:form >
<apex:pageBlock title="Task History">
<apex:pageBlockTable value="{!taskinfo}" var="task">
<apex:column value="{!task.activitydate}"/>
<apex:column value="{!task.subject}"/>
<apex:column value="{!task.description}"/>
<apex:column value="{!task.status}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Event History">
<apex:pageblockTable value="{!eventinfo}" var="event">
<apex:column value="{!event.activitydate}"/>
<apex:column value="{!event.subject}"/>
<apex:column value="{!event.description}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

And heres the extension I wrote 
 
public with sharing class CombinedActivitiesSortingExtension {
    
    Id oppID;
    private final ID taskid;
    Public List<Task> taskinfo {get;set;}
    Public List<Event> eventinfo {get;set;}
    
    
    
    Public CombinedActivitiesSortingExtension(ApexPages.StandardController stdController) {
        
        oppID = stdController.getId();
        taskid = stdController.getId();
        
        
        taskinfo =   [SELECT ActivityDate, Subject, Description, Status
                      FROM Task
                      WHERE Id= :oppID
                      ORDER BY ActivityDate desc];
        
        eventinfo = [SELECT ActivityDate, Subject, Description
                     FROM Event
                     WHERE Id= :oppID
                     ORDER BY ActivityDate desc];
                     
                       
                     
      
            
   
    }


}

Any help would be super appreciated.
Thank you!







 
Hey all!

With some help I wrote this custom trigger that allows our reps to list some additional contacts and their information on Lead records that then transform into Contact records on lead convert.
 
trigger CreateMoreLeadContacts on Lead (after update) {

list < Contact > listContacts = new List < Contact>();

for(Lead objLead : trigger.new) {

if(objlead.IsConverted && !trigger.oldMap.get(objLead.Id).IsConverted) {

Contact c1=New Contact(
LastName=objLead.Secondary_Lead_Contact_Name__c,
Phone=objLead.Secondary_Lead_Phone__c,
Email=objLead.Secondary_Lead_Email__c);

c1.AccountId = objLead.ConvertedAccountId;
listContacts.add(c1);

Contact c2=New Contact(
LastName=objLead.Tertiary_Lead_Contact_Name__c,
Phone=objLead.Tertiary_Lead_Phone__c,
Email=objLead.Tertiary_Lead_Email__c);

c2.AccountId = objLead.ConvertedAccountId;
listContacts.add(c2);

     }
        
    }
    
    if ( listContacts.size() > 0 )
        insert listContacts;

}
The trigger works just fine and as expected... however, i've now indentified an issue when trying to convert a Lead when no data is present in both "Secondary Contact Lead Name" & "Tertiary Contact Lead Name".

Only way to get around this with the current trigger is to list dummy Contact name data in the custom lead fields before the Lead gets converted.

What would be the best way to encapsulate the trigger so that it doesn't fire when names aren't listed / just when one additional contact is listed? 



 
Hey all,

I'm hoping someone could help me identify what's wrong with this trigger I wrote. To preface, i'm very new to the Apex development/coding side of SF (only my 2nd week doing this!).

Several agents in the company I work for want to have a way to list up to two additional points of contact on their Lead records that then convert over into Contact records when the Lead is converted. After a week or so of digging into this and searching I feel like i'm close to a solution (but not quite)

Here is the trigger as I have it right now; 0% code coverage currently (it was at one point 77% before I updated the test unit to accompany it)
 
trigger MoreContacts_Trigger on Lead (after update) {

List<Lead> newLeads = trigger.new;
Map<Id, Lead> mOldLeads = trigger.oldMap;
Lead oldLead;

Set<Id> convertedAccountIds = new Set<Id>();
Set<Id> convertedContactIds = new Set<Id>();

for (Lead l : newLeads) {

    if (l.convertedAccountId != null) {
        convertedAccountIds.add(l.convertedAccountId);
    }

    if (l.convertedContactId != null) {
        convertedContactIds.add(l.convertedContactId);
    }
    }

    Account accounts =
    [SELECT Id, Name
     FROM Account
     WHERE Id IN : convertedAccountIds];

for(Lead l : Trigger.New){
If(l.IsConverted){


Contact c1=New Contact(
LastName=l.Secondary_Lead_Contact_Name__c,
Phone=l.Secondary_Lead_Phone__c,
Email=l.Secondary_Lead_Email__c, 
AccountId=accounts.id);

insert c1;

Contact c2=New Contact(
LastName=l.Tertiary_Lead_Contact_Name__c,
Phone=l.Tertiary_Lead_Phone__c,
Email=l.Tertiary_Lead_Email__c, 
AccountId=accounts.id);

insert c2;

}}}

And here is the class (100% code coverage with some help from another developer, was 0% before).
@isTest

public class MoreContacts_TriggerClass{
static testmethod void MoreContacts_TriggerClass(){

Lead Lead = new Lead(
LastName='Test',
Company='TestCompany',
Email='test@test.com',
Phone='9996663333'

);

insert Lead;

Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(lead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('Qualified');

Database.LeadConvertResult lcr = Database.convertLead(lc, false);

}
}

I'm not sure where to go from here but I want to figure out whats wrong, hoping somone might be able to help me pin-point the error. Thanks in advance!