• law
  • NEWBIE
  • 75 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 31
    Questions
  • 61
    Replies
I would like to not Map the whole contact object, but only map contacts where the RecordType = 'ID'.  Any help would be greatly appreciated.
Method is below.

      public void doAutoSubscribe(Map<Id, Contact> contactMap) {
     
        List<Subscription__c> existingSubs;       
        Set<ID> advisorIDs = contactMap.keySet();

    
        Map<Id,Set<Id>> alreadySubscribed = new Map<Id,Set<Id>>();
        List<Subscription__c> newSubs = new List<Subscription__c>();
        
        existingSubs =  [SELECT Advisor__c, Publication__c, Id FROM Subscription__c where Advisor__c in :advisorIDs and Publication__r.Subscribe_On_Advisor_Create__c = true];

    for(Id id: advisorIds) {
      alreadySubscribed.put(id, new Set<id>());
    }
    
    for(Subscription__c sub : existingSubs) {
      Set<id> currentSubcriptions = new Set<id>();
      if (alreadySubscribed.containsKey(sub.Advisor__c)) {
        currentSubcriptions = alreadySubscribed.get(sub.Advisor__c);        
      }
      currentSubcriptions.add(sub.Publication__c);
      alreadySubscribed.put(sub.Advisor__c, currentSubcriptions);          
    }
   
    List<Publication__c> pubs;
    pubs = [ Select id from Publication__c where Subscribe_On_Advisor_Create__c = true ] ;
          
       for(Publication__c p : pubs) {
         for(Id id : advisorIds) {
           Set<id> currentSubscriptions = alreadySubscribed.get(id);
           System.debug('THIS IS THE RECORDTYPE NAME 2----->'+RTName);
           //if (!currentSubscriptions.contains(p.id) ) {  
           
 
           if (RTName == 'ID' && !currentSubscriptions.contains(p.id)) {   // Add check for ID RecordType  Lreed 09/23/2014
             System.debug('Advisor Record TypeName 3----->'+ RTName);
             Subscription__c sub = new Subscription__c();
             sub.Advisor__c = id;
             sub.Publication__c = p.id;
             sub.Subscribed__c = true;
             newSubs.add(sub);
           }
         }
       }
       System.debug('NEW SUBS --------- >' + newSubs.size());
       System.debug('NEW SUBS EMPTY --------- >' + newSubs.isEmpty());
       if (!newSubs.isEmpty())  {
            System.debug('INSERT NEW SUBS --------- >');   
         insert newSubs; 
       }
       
     }
  • October 28, 2014
  • Like
  • 0
I have a trigger that fires on Insert/Update.  Works fine when testing this by entering contacts or updating contacts manually one at a time.
However, when there is a batch update it seems to ignore this one  IF condition in my code.

Anyone ever experience this?
  • October 22, 2014
  • Like
  • 0
I have a class file that shows 100% coverage when I run its Test Class file.  However, when I attempt to deploy any new code this same class file only shows 57% coverage.  Anyone experience this type of issue or have a resolution?

Thanks in advance
  • October 13, 2014
  • Like
  • 0
In the code snippet below I am able to see the Contact ID in the variable advisorIDS.  What would I add to the code to see another field on the contact record?
Thanks in Advance

public void doAutoSubscribe(Map<Id, Contact> contactMap) {
    
        Set<ID> advisorIDs = contactMap.keySet();
        system.debug(' ADVISOR ID----- >' + advisorIds);       

}
  • September 18, 2014
  • Like
  • 0
The below code works fine.  However you will notice that I do have a SOQL inside of a loop.
In an attempt to avoid issues down the line, I need to move this outisde the loop.  Any ideas on how to do this an still reference  the current b.Candidate__c(which is the contactID attached to the current Book_of_Business__c record.     Thanks in Advance

trigger BOBChange on Book_of_Business__c (before insert, before update) {
 
List<Quintile__c> Quintiles = new List<Quintile__c> ();
List<Book_of_Business__c> bob=[SELECT Id,Name,Candidate__c  from Book_of_Business__c ];
List<Contact> Contacts = new List<Contact> ();

Quintiles = [Select Quintile__c, T12_Min__c,T12_Max__c, LOS_Min__c, LOS_Max__c
             FROM      
                Quintile__c
             WHERE
                start_date__c <= today AND
                End_date__c > today];
               
              
    If (bob.size() > 0){
        for (Book_of_Business__c b : Trigger.new) {
            system.debug('BOB ------------- > ' + b.Id);
            system.debug('CandidateID ------------- > ' + b.Candidate__c);
            Contacts = [Select ID, Quintile_LOS__c, Total_years_as_a_rep__c, Producer_LOS__c,FirstName, LastName from Contact where ID =: b.Candidate__c];                 
            for (Contact c : Contacts){
             system.debug('C  ID ------------- > ' + c.Id);
                for (Quintile__c q : Quintiles) {
                 if(b.Candidate__c == c.ID &&
                  q.T12_Min__c <= b.Post_Haircut_T_12__c &&
                        q.T12_Max__c > b.Post_Haircut_T_12__c &&
                        q.LOS_Min__c <= c.Quintile_LOS__c &&
                        q.LOS_Max__c > c.Quintile_LOS__c) {
                             b.Quintile__c = q.Quintile__c;   // update BOB Quintile Field
                       System.debug(' Q.Quintile__c --------- >' + Q.Quintile__c);
                             }
                }

            }
        }
    }
}
  • September 05, 2014
  • Like
  • 0
Hello All

The code below executes as expected, however when attempting to deploy I receive  a SOQL 101 error.
I believe it is due to the bolded line of code below inside of the Opportunity for loop.  How can I move this outside the loop
and still match the candidate to the candidate on the opportunity?

Thanks in Advance



trigger OpportunityChange on Opportunity (before insert, before update) {

List<Quintile__c> Quintiles = new List<Quintile__c> ();  
Quintiles = [Select Quintile__c, T12_Min__c,T12_Max__c, LOS_Min__c, LOS_Max__c
       FROM 
              Quintile__c
      WHERE
        start_date__c <= today AND
       End_date__c > today];
    
  for (Opportunity o : Trigger.new) {
     List<Contact> Contacts = new List<Contact> (); 
     Contacts = [Select ID, Total_years_as_a_rep__c from Contact where ID =: o.Contact__c limit 1];
     for (Contact c : Contacts){
         for (Quintile__c q : Quintiles) {
              if(q.T12_Min__c <= o.Post_Haircut_T12__c &&
              q.T12_Max__c > o.Post_Haircut_T12__c &&
              q.LOS_Min__c <= c.Total_years_as_a_rep__c &&
             q.LOS_Max__c > c.Total_years_as_a_rep__c) {
          o.Quintile__c = q.Quintile__c;
        }
          }
   }
     }
}
  • May 19, 2014
  • Like
  • 0
I receive the following compile error : Description Resource Path Location Type
Save error: Illegal assignment from Schema.SObjectField to Decimal ContactChanges.trigger EAR AFTER REFRESH 3_05_2014/src/triggers line 520 Force.com save problem

Any and all help greatly appreciated!


Code below:

List<Quintile__c> q = [Select Quintile__c, T12_Min__c, T12_Max__c,Los_Min__c,LOS_Max__c,Start_Date__c,End_Date__c
                    from Quintile__c
           where start_date__c <= today  and end_date__c > today];
         
         
            if(!q.isEmpty()){
    if (c.Total_years_as_a_rep__c != 0 &&  c.Total_years_as_a_rep__c != null  && c.Estimated_T_12__c != 0 && c.Estimated_T_12__c != null &&
              c.Estimated_T_12__c >= Quintile__c.T12_Min__c &&
              c.Estimated_T_12__c < Quintile__c.T12_Max__c &&
     c.Total_years_as_a_rep__c >= Quintile__c.LOS_Min__c &&
     c.Total_years_as_a_rep__c < Quintile__c.LOS_Max__c
              ){
              c.Estimated_Quintile__c  = Quintile__c.Quintile__c;
          }
   }else
   {
         //handler code for no matching account 
            }
  • April 25, 2014
  • Like
  • 0

I have the following line of code in a trigger. It updates but I have a red x where the image should be.  I have verified that the image displays and exists.

Any help would be appreciated.

 

 c.Conservation_Duplicate__c = '<img src="https://c.cs16.content.force.com/servlet/servlet.FileDownload?file=015f00000000tji></img>';

 

Lawrence

  • October 30, 2013
  • Like
  • 0

I have a trigger on the a custom object called offer.  Within this trigger I need to verify that ther exist no OTHER offers with the same status as the current Offer.  There is only one offer, this is the current offer.  I create a map to store the results and this one offer is of course in the map.

 

How do I disregard the current record when its included in the map.

  • October 23, 2013
  • Like
  • 0

I have an Offer Trigger(before insert before update).   When I change the current offer status to 'Offer Declined'  I need to check to see if there are any other offers  with a status other than 'Offer Declined'. The problem is that my  query returns the exact offer that I just edited  with the  previous Status before I change it to 'offer declined'.  The result should return  NULL as there are no other offers with a Status not equal to 'Offer Declined'.      My query is pulling back the offer with the status before the status was changed.

 

I tried changing the trigger to after update, however this causes an entire section of code not to execute.

 

Any help would be appreciated.

  • October 23, 2013
  • Like
  • 0

In the highlighted query below.  The result only returns 1 of 2 records.  Any help into how to resolve this.  There does exist 2 opportunities in this contact.  Thanks in Advance.

 

 

public OfferStatusChangeFlowHelper (List <Offer__c> triggerNew) {

if (triggerNew != null)
this.triggerNew = triggerNew;

//get opps and con ids
for (Offer__c offer : triggerNew) {
contactIds.add(offer.Candidate_Name__c);
oppIds.add (offer.opportunity__c);
}

for (Offer__c o:[SELECT Id, Name, Offer_Status__c, Candidate_Name__c FROM Offer__c WHERE Candidate_Name__c IN :contactIds
AND (Offer_Status__c = 'Offer Accepted' OR Offer_Status__c = 'Offer Extended') ]) {
//check map for contact id
if (contactOffersMap.get(o.Candidate_Name__c)==null) {//no entry yet
contactOffersMap.put (o.Candidate_Name__c, new List <Offer__c> {o});
} else {//otherwise get list of opps and add a new one
contactOffersMap.get(o.Candidate_Name__c).add(o);
}
}

for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds AND isClosed = false]) {// comment out to test bring back open and closed for first part of step 9.
System.debug('OPPORTUNITY IDS: ' + oppIds);
//for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds]) {
//check map for contact id
if (oppMap.get(o.Contact__c)==null) {//no entry yet
oppMap.put (o.Contact__c, new List <Opportunity> {o});
} else {//otherwise get list of opps and add a new one
oppMap.get(o.Contact__c).add(o);
}
}
}

  • October 17, 2013
  • Like
  • 0

I am receiving the following error.  I have included the code after the error.  Any help would be appreciated.

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ContactOpportunityStage caused an unexpected exception, contact your administrator: ContactOpportunityStage: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ContactOpportunityStage: line 13, column 1

 

 

 

trigger ContactOpportunityStage on Opportunity (after insert, before update) {
    
    SingletonResource singleton = SingletonResource.getInstance();
    Stage_And_Status__c oppStages = Stage_And_Status__c.getInstance('Opportunity Stages');
    Stage_And_Status__c contactStatuses = Stage_And_Status__c.getInstance('Contact Statuses');
    // Opportunity stages
    Map<String, Integer> oppStageMap = new Map<String, Integer> {   /////LINE 13
        oppStages.Open_Meeting__c => 1,
        oppStages.Closed_Meeting_Withdrew__c => 2,
        oppStages.Closed_Meeting_AMPF_Declined__c => 3,
        oppStages.Open_Due_Diligence__c => 4,
        oppStages.Closed_DD_Withdrew__c => 5,
        oppStages.Closed_DD_Background__c => 6,
        oppStages.Closed_DD_Hiring_Mgr__c => 7,
        oppStages.Closed_DD_Governance__c => 8,
        oppStages.Open_Offer_Extended__c => 9,
        oppStages.Closed_Offer_Declined__c => 10,
        oppStages.Closed_Offer_Expired__c => 11,
        oppStages.Closed_Offer_Accepted__c => 12
        //oppStages.Open_Offer_Generation__c => 3,
       // oppStages.Open_Offer_Accepted__c => 12,
        //oppStages.Closed_Won_Hired__c => 13        
    };

  • July 31, 2013
  • Like
  • 0

Has anyone experience troubled with the cvent integrations that would cause attendee number to calculate incorrectly or be overwritten with a wrong number?

 

Thanks in Advance

 

  • July 12, 2013
  • Like
  • 0

I have two buttons on the contact screen.  Log a Call and Log a Meeting.  When these are selected the corresponding screen to log a call or meeting comes up.

Upon saving the call or meeting a trigger is called on insert /update/delete.  This trigger updates a Status field on the contact record.  The updates works however, the contact screen will not show this field as updated until I hit F5.   I have reproduced this in Both FireFox and Chrome.

 

Thanks in advance for your help.

Lawrence

  • July 10, 2013
  • Like
  • 0

I am attemtping to use the  trigger.old  to compare the previous owner value to the new owner value.  However in the code below t.owner in null.

any assistance would be greatly appreciated

 

for (Task t : Trigger.new) {
system.debug('NEW OwnerID' + t.Owner);
if(t.Owner != null && System.Trigger.oldMap.get(t.id).Owner == t.Owner){

Map<Id, Contact> contacts = new Map<Id, Contact> ([Select Id, Phone, MobilePhone, Status__c, RecordTypeId, AccountId, LeadSource, Last_Comment__c
From Contact
Where Id IN :contactIds]);
Map<Id, Contact> desiredContacts = new Map<Id, Contact> ();
for (Contact c : contacts.values()) {

if (RecordType == '012U0000000L2TJIA0'&& c.Status__c == 'Prospect: Not Contacted' ) { //Call
c.Status__c = 'Prospect: Contacted';
desiredContacts.put(c.Id, c);

}else if (RecordType == '012U0000000XcyZIAS' && c.Status__c == 'Candidate: Qualified') { //Meeting
c.Status__c = 'Candidate: Meeting';
desiredContacts.put(c.Id, c);
//Meeting //Prospect
}
if (Trigger.isInsert) {
if (RecordType == '012U0000000XcyZIAS' && c.RecordTypeId == '012U0000000Y3ybIAC' && c.Status__c != 'Candidate: Qualified') { /// 02-12-2013 lreed...If user has not qualified lead show error message
trigger.new[0].adderror('You Must Qualify The Candidate Before Logging A Meeting!');

}else if (RecordType == '012U0000000XcyZIAS' && c.RecordTypeId == '012U0000000Y3ybIAC' && c.Status__c != 'Prospect: Contacted')
{ /// 02-12-2013 lreed...If user has not qualified lead show error message
trigger.new[0].adderror('Please Log a Call Before Qualifying The Candidate!');
}
}
}

  • June 27, 2013
  • Like
  • 0

Hello 

 

I know this usually happens when  you have your SOQL in a loop.  However in the code below I do not see this.  The code is below. I have highlighted the line of SQL in Question.

 

trigger UpdateFieldsFromLogMeeting on Task (after insert, after update) {
SingletonResource singleton = SingletonResource.getInstance();

Id callRecId = singleton.callRecId;
Id meetingRecId = singleton.meetingRecId;
Id faceRecId = singleton.faceToFaceRecId;
Id prospectRecId = singleton.prospectRecId;
Id candidateRecId = singleton.candidateRecId;
Id sysAdminId = singleton.sysAdminId;
list<Id> ContactIds = new List<Id>();
list<Id> OwnerIds = new List<Id>();

System.Debug('Go through tasks');
for(task t : Trigger.new) {
ContactIds.add(t.WhoId);
System.Debug('Task Owner: ' + t.OwnerId);
OwnerIds.add(t.OwnerId);
}

//------------------------------------------------
map<id,contact> contacts = new map<id,contact>();
for(task record:trigger.new) {
if(record.whoid!=null&&record.whoid.getsobjecttype()==contact.sobjecttype) {
contacts.put(record.whoid,null);
}
}
contacts.putall([select Id,Phone,FirstName,Email, EAR_Assist__c, EAR_Assist_Name__c, EAR_Validate__c, EAR_Validation_Date__c, LeadSource, EARAssistTask__c from contact where id in :contacts.keyset()]);
//------------------------------------------------
map<id,contact> contactstoupdate = new map<id,contact>();
Map<Id,User> users = new Map<Id,User>();

for(User u : [Select id, Name, UserRole.Name from User u where u.id in :OwnerIds]) {
System.Debug('UserRole.Name loop:' + u.userrole.name);
users.put(u.id, u);
}

for(task t:trigger.new) {


if (t.Status == 'Completed' && (t.Type == 'Face-to-Face Meeting' || t.Type == 'Follow Up') &&
t.RecordTypeId != callRecId){
//Select the contact associated with the new Meeting
//system.debug ('VALUE OF I = ' + i);

Contact c = contacts.get(t.whoid);
if(c==null) {
continue;
}


//Update fields in the contact from values in the Meeting Logged
c.Viability__c = t.Viability__c;
c.Estimated_T_12__c=t.Estimated_T_12__c;
c.Estimated_AUM__c=t.Estimated_AUM__c;


String roleName = '';

if ( users.containsKey(t.Ownerid) ) {
User u = users.get(t.Ownerid);
// System.Debug('User ' + u.Name);
roleName = u.UserRole.Name.toLowerCase();
// System.Debug('ROLE ' + roleName);

} else {
System.Debug('Owner Not Found');
}

if ( roleName.contains ('regional dir-ear')) {
System.Debug('Role Name = ' + roleName);
if (c.OwnerId != sysAdminId ) {
c.EAR_Assist__c = true;
c.EAR_Assist_Name__c = t.OwnerId;
c.EARAssistTask__c = t.id;

if ( c.LeadSource == 'Self-Sourced') {
c.EAR_Validate__c = true;
c.EAR_Validation_Date__c = t.ActivityDate;
}
} else if ( c.EAR_Assist_Name__c == t.Ownerid ) {
c.EAR_Validate__c = true;
if (c.EAR_Validation_Date__c == null || t.ActivityDate > c.EAR_Validation_Date__c) {
c.EAR_Validation_Date__c = t.ActivityDate;
}
}

}


contactstoupdate.put(c.id,c);

}

}

if ( contactsToUpdate.size() != 0) {
update contactstoupdate.values();
}
}

  • May 13, 2013
  • Like
  • 0

 

Hello 

 

I receive the following error when running a test class:

EXCEPTION_THROWN|[EXTERNAL]|System.UnexpectedException: No more than one executeBatch can be called from within a testmethod.  Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

 

Test Class is below. Any help wouldbe greatly appreciated.

 

public class TestScheduleBatchOnDSTADVISORUpdate {

//*****************************************************************************************
//*****************************************************************************************
/* Method # 1
Name : testScheduleBatchOnDSTADVISORUpdate
Function: Tests the functionality of the Apex Class
for the scheduling of the Batch Class
ScheduleBatchOnDSTADVISORUpdate

*/
public static TestMethod void testScheduleBatchOnDSTADVISORUpdate()

{
DateTime currTime = DateTime.now();
Integer min = currTime.minute();
Integer hour = currTime.hour();
String sch;


//Scheduling the class
if(min <= 58)
sch = '0 '+ (min + 1) + ' ' + hour + ' * * ? '+ currTime.year();
else
sch = '0 0 '+ (hour + 1) + ' * * ? '+ currTime.year();

Boolean runTestMethod;
//***************Test Starts****************
Test.startTest();

CAD_DST_Advisors__c dst=new CAD_DST_Advisors__c();
dst.name='Test_DST_ScheduleBatchOnDSTADVISORUpdate';
dst.CRD__c='5521521';
dst.REP_LAST_NAME__c='Testing';
dst.REP_WORK_CITY__c='Test_City';
dst.CRDChanged__c=true;
dst.UIDDirectlyFromDST__c=true;
insert dst;

// Creating the instance of the Apex Class to be tested "ScheduleBatchOnDSTADVISORUpdate"

ScheduleBatchOnDSTADVISORUpdate obj = new ScheduleBatchOnDSTADVISORUpdate ();
String jobId = system.schedule('test', sch, obj);

//CronTrigger : Represents a scheduled Apex job
CronTrigger ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger where id = :jobId limit 199];


System.assertEquals(sch, ct.CronExpression);
database.executeBatch(new BatchOnDSTUpdateADVISORCONTROLLER('select id,CRD__c, CRD_P__C,UID__C,REP_LAST_NAME__c,Email_p__c, LastName_City_State_Combo__c, REP_PRIMARY_CONTACT_ID__c ,REP_WORK_CITY__c ,REP_WORK_STATE__c, REP_EMAIL_ADDRS__c,Is_UID_Populated__c,uiddirectlyfromDST__c from CAD_DST_Advisors__c where CRDChanged__c=true and (Is_UID_Populated__c=true or UIDDirectlyFromDST__c=true)limit 199'));

System.abortJob(JobID);
//Assert Statements
System.assertequals('5521521',dst.CRD__c,'CRD__c didnot work');
System.assertequals('Test_DST_ScheduleBatchOnDSTADVISORUpdate',dst.name,'Name didnot work');
System.assertequals('Testing',dst.REP_LAST_NAME__c,'REP_LAST_NAME__c didnot work');
System.assertequals(true,dst.CRDChanged__c,'CRDChanged__c didnot work');
System.assertequals(true,dst.UIDDirectlyFromDST__c,'UIDDirectlyFromDST__c didnot work');

Test.stopTest();
}



//***************Test Ends****************


}

 

  • May 06, 2013
  • Like
  • 0

Hello

I have the following two sections of code that I need to understand. Initiative_settings__c is not a standard object or custom object that I can see in SF. But I can see the scheme through Eclipse. The scheme has fields in it. One of which is ANN_Marketing__c which is referenced in the second set of code? How is this sObject Built and how do I add additional fields to it? 

private Initiative_Settings__c getInitiativeSettings() {
return Initiative_Settings__c.getInstance();
}

public boolean getContainsAnnMarketingCampaigns() {
return getInitiativeSettings().ANN_Marketing__c && !getAnnMarketingCampaigns().isEmpty();
}

public List getAnnMarketingCampaigns() {
return filterList('ANN Marketing');
}

  • May 02, 2013
  • Like
  • 0

Hello All I am receiving the following error: System.ListException: List index out of bounds: 2  Trigger.UpdateFieldsFromLogMeeting: line 37, column 1: []

 

The value of i at the time of the error is  2.   Not sure what I need to do in the loop to resolve this.

Any help would be much appreciated.   Code is below.   Line 37 is " Contact c = contacts.get(i);"

 

   for (Integer i = 0; i < Trigger.new.size(); i++) {

             Task t = Trigger.new.get(i);
             if (t.Status == 'Completed' && (t.Type == 'Face-to-Face Meeting' || t.Type == 'Follow Up') &&
                t.RecordTypeId != callRecId){
                   //Select the contact associated with t he new Meeting
                   system.debug ('VALUE OF I = ' + i);
                   Contact c = contacts.get(i);
                   
              
                   c.Viability__c = t.Viability__c;
                   c.Estimated_T_12__c=t.Estimated_T_12__c;
                   c.Estimated_AUM__c=t.Estimated_AUM__c;
                   
                   String roleName = '';
                   if ( users.containsKey(t.Ownerid) ) {
                        User u = users.get(t.Ownerid);
                        System.Debug('User ' + u.Name);
                        roleName = u.UserRole.Name.toLowerCase();
                        System.Debug('ROLE ' + roleName);                   
                   } else {
                        System.Debug('Owner Not Found');
                   }
                   
                   
                    if ( roleName.contains ('regional dir-ear')) {
                       System.Debug('Role Name = ' + roleName);
                        if (c.EAR_Assist__c == false || c.EAR_Assist_Name__c == null || c.EARAssistTask__c == t.id  ) {
                            
                            c.EAR_Assist__c = true;
                            c.EAR_Assist_Name__c = t.Ownerid;
                            c.EARAssistTask__c = t.id;
                            
                            if ( c.LeadSource == 'Self-Sourced') {
                                c.EAR_Validate__c = true;
                                c.EAR_Validation_Date__c = t.ActivityDate;
                            }                               
                        } else if ( c.EAR_Assist_Name__c == t.Ownerid ) {
                            c.EAR_Validate__c = true;                           
                            if (c.EAR_Validation_Date__c == null || t.ActivityDate > c.EAR_Validation_Date__c) {                            
                                c.EAR_Validation_Date__c = t.ActivityDate;
                            }                                                           
                        }   
                    
                   }
                                      
                  contactsToUpdate.add(c);

             }

         }

  • March 06, 2013
  • Like
  • 0
I have a trigger that fires on Insert/Update.  Works fine when testing this by entering contacts or updating contacts manually one at a time.
However, when there is a batch update it seems to ignore this one  IF condition in my code.

Anyone ever experience this?
  • October 22, 2014
  • Like
  • 0
I have a class file that shows 100% coverage when I run its Test Class file.  However, when I attempt to deploy any new code this same class file only shows 57% coverage.  Anyone experience this type of issue or have a resolution?

Thanks in advance
  • October 13, 2014
  • Like
  • 0
In the code snippet below I am able to see the Contact ID in the variable advisorIDS.  What would I add to the code to see another field on the contact record?
Thanks in Advance

public void doAutoSubscribe(Map<Id, Contact> contactMap) {
    
        Set<ID> advisorIDs = contactMap.keySet();
        system.debug(' ADVISOR ID----- >' + advisorIds);       

}
  • September 18, 2014
  • Like
  • 0
The below code works fine.  However you will notice that I do have a SOQL inside of a loop.
In an attempt to avoid issues down the line, I need to move this outisde the loop.  Any ideas on how to do this an still reference  the current b.Candidate__c(which is the contactID attached to the current Book_of_Business__c record.     Thanks in Advance

trigger BOBChange on Book_of_Business__c (before insert, before update) {
 
List<Quintile__c> Quintiles = new List<Quintile__c> ();
List<Book_of_Business__c> bob=[SELECT Id,Name,Candidate__c  from Book_of_Business__c ];
List<Contact> Contacts = new List<Contact> ();

Quintiles = [Select Quintile__c, T12_Min__c,T12_Max__c, LOS_Min__c, LOS_Max__c
             FROM      
                Quintile__c
             WHERE
                start_date__c <= today AND
                End_date__c > today];
               
              
    If (bob.size() > 0){
        for (Book_of_Business__c b : Trigger.new) {
            system.debug('BOB ------------- > ' + b.Id);
            system.debug('CandidateID ------------- > ' + b.Candidate__c);
            Contacts = [Select ID, Quintile_LOS__c, Total_years_as_a_rep__c, Producer_LOS__c,FirstName, LastName from Contact where ID =: b.Candidate__c];                 
            for (Contact c : Contacts){
             system.debug('C  ID ------------- > ' + c.Id);
                for (Quintile__c q : Quintiles) {
                 if(b.Candidate__c == c.ID &&
                  q.T12_Min__c <= b.Post_Haircut_T_12__c &&
                        q.T12_Max__c > b.Post_Haircut_T_12__c &&
                        q.LOS_Min__c <= c.Quintile_LOS__c &&
                        q.LOS_Max__c > c.Quintile_LOS__c) {
                             b.Quintile__c = q.Quintile__c;   // update BOB Quintile Field
                       System.debug(' Q.Quintile__c --------- >' + Q.Quintile__c);
                             }
                }

            }
        }
    }
}
  • September 05, 2014
  • Like
  • 0
Hello All

The code below executes as expected, however when attempting to deploy I receive  a SOQL 101 error.
I believe it is due to the bolded line of code below inside of the Opportunity for loop.  How can I move this outside the loop
and still match the candidate to the candidate on the opportunity?

Thanks in Advance



trigger OpportunityChange on Opportunity (before insert, before update) {

List<Quintile__c> Quintiles = new List<Quintile__c> ();  
Quintiles = [Select Quintile__c, T12_Min__c,T12_Max__c, LOS_Min__c, LOS_Max__c
       FROM 
              Quintile__c
      WHERE
        start_date__c <= today AND
       End_date__c > today];
    
  for (Opportunity o : Trigger.new) {
     List<Contact> Contacts = new List<Contact> (); 
     Contacts = [Select ID, Total_years_as_a_rep__c from Contact where ID =: o.Contact__c limit 1];
     for (Contact c : Contacts){
         for (Quintile__c q : Quintiles) {
              if(q.T12_Min__c <= o.Post_Haircut_T12__c &&
              q.T12_Max__c > o.Post_Haircut_T12__c &&
              q.LOS_Min__c <= c.Total_years_as_a_rep__c &&
             q.LOS_Max__c > c.Total_years_as_a_rep__c) {
          o.Quintile__c = q.Quintile__c;
        }
          }
   }
     }
}
  • May 19, 2014
  • Like
  • 0
I receive the following compile error : Description Resource Path Location Type
Save error: Illegal assignment from Schema.SObjectField to Decimal ContactChanges.trigger EAR AFTER REFRESH 3_05_2014/src/triggers line 520 Force.com save problem

Any and all help greatly appreciated!


Code below:

List<Quintile__c> q = [Select Quintile__c, T12_Min__c, T12_Max__c,Los_Min__c,LOS_Max__c,Start_Date__c,End_Date__c
                    from Quintile__c
           where start_date__c <= today  and end_date__c > today];
         
         
            if(!q.isEmpty()){
    if (c.Total_years_as_a_rep__c != 0 &&  c.Total_years_as_a_rep__c != null  && c.Estimated_T_12__c != 0 && c.Estimated_T_12__c != null &&
              c.Estimated_T_12__c >= Quintile__c.T12_Min__c &&
              c.Estimated_T_12__c < Quintile__c.T12_Max__c &&
     c.Total_years_as_a_rep__c >= Quintile__c.LOS_Min__c &&
     c.Total_years_as_a_rep__c < Quintile__c.LOS_Max__c
              ){
              c.Estimated_Quintile__c  = Quintile__c.Quintile__c;
          }
   }else
   {
         //handler code for no matching account 
            }
  • April 25, 2014
  • Like
  • 0

I have an Offer Trigger(before insert before update).   When I change the current offer status to 'Offer Declined'  I need to check to see if there are any other offers  with a status other than 'Offer Declined'. The problem is that my  query returns the exact offer that I just edited  with the  previous Status before I change it to 'offer declined'.  The result should return  NULL as there are no other offers with a Status not equal to 'Offer Declined'.      My query is pulling back the offer with the status before the status was changed.

 

I tried changing the trigger to after update, however this causes an entire section of code not to execute.

 

Any help would be appreciated.

  • October 23, 2013
  • Like
  • 0

In the highlighted query below.  The result only returns 1 of 2 records.  Any help into how to resolve this.  There does exist 2 opportunities in this contact.  Thanks in Advance.

 

 

public OfferStatusChangeFlowHelper (List <Offer__c> triggerNew) {

if (triggerNew != null)
this.triggerNew = triggerNew;

//get opps and con ids
for (Offer__c offer : triggerNew) {
contactIds.add(offer.Candidate_Name__c);
oppIds.add (offer.opportunity__c);
}

for (Offer__c o:[SELECT Id, Name, Offer_Status__c, Candidate_Name__c FROM Offer__c WHERE Candidate_Name__c IN :contactIds
AND (Offer_Status__c = 'Offer Accepted' OR Offer_Status__c = 'Offer Extended') ]) {
//check map for contact id
if (contactOffersMap.get(o.Candidate_Name__c)==null) {//no entry yet
contactOffersMap.put (o.Candidate_Name__c, new List <Offer__c> {o});
} else {//otherwise get list of opps and add a new one
contactOffersMap.get(o.Candidate_Name__c).add(o);
}
}

for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds AND isClosed = false]) {// comment out to test bring back open and closed for first part of step 9.
System.debug('OPPORTUNITY IDS: ' + oppIds);
//for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds]) {
//check map for contact id
if (oppMap.get(o.Contact__c)==null) {//no entry yet
oppMap.put (o.Contact__c, new List <Opportunity> {o});
} else {//otherwise get list of opps and add a new one
oppMap.get(o.Contact__c).add(o);
}
}
}

  • October 17, 2013
  • Like
  • 0

I am receiving the following error.  I have included the code after the error.  Any help would be appreciated.

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ContactOpportunityStage caused an unexpected exception, contact your administrator: ContactOpportunityStage: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ContactOpportunityStage: line 13, column 1

 

 

 

trigger ContactOpportunityStage on Opportunity (after insert, before update) {
    
    SingletonResource singleton = SingletonResource.getInstance();
    Stage_And_Status__c oppStages = Stage_And_Status__c.getInstance('Opportunity Stages');
    Stage_And_Status__c contactStatuses = Stage_And_Status__c.getInstance('Contact Statuses');
    // Opportunity stages
    Map<String, Integer> oppStageMap = new Map<String, Integer> {   /////LINE 13
        oppStages.Open_Meeting__c => 1,
        oppStages.Closed_Meeting_Withdrew__c => 2,
        oppStages.Closed_Meeting_AMPF_Declined__c => 3,
        oppStages.Open_Due_Diligence__c => 4,
        oppStages.Closed_DD_Withdrew__c => 5,
        oppStages.Closed_DD_Background__c => 6,
        oppStages.Closed_DD_Hiring_Mgr__c => 7,
        oppStages.Closed_DD_Governance__c => 8,
        oppStages.Open_Offer_Extended__c => 9,
        oppStages.Closed_Offer_Declined__c => 10,
        oppStages.Closed_Offer_Expired__c => 11,
        oppStages.Closed_Offer_Accepted__c => 12
        //oppStages.Open_Offer_Generation__c => 3,
       // oppStages.Open_Offer_Accepted__c => 12,
        //oppStages.Closed_Won_Hired__c => 13        
    };

  • July 31, 2013
  • Like
  • 0

I have two buttons on the contact screen.  Log a Call and Log a Meeting.  When these are selected the corresponding screen to log a call or meeting comes up.

Upon saving the call or meeting a trigger is called on insert /update/delete.  This trigger updates a Status field on the contact record.  The updates works however, the contact screen will not show this field as updated until I hit F5.   I have reproduced this in Both FireFox and Chrome.

 

Thanks in advance for your help.

Lawrence

  • July 10, 2013
  • Like
  • 0