• Josh Harsh
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Concept Services, LTD

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 14
    Replies
Hello,

I currently have a trigger to count the number of tasks related to an Account. The trigger works for the most part, it does not work when an Account is merged with another Account. Can someone assist in helping me find why the code is not recounting the activity upon the change of the What.ID on the task?

Below is the code.


trigger SumTasksTrigger on Task (after insert, after update, after delete) {

    set<Id> set_id = new set<Id>();
    
    List<Account> acc_list = new List<Account>();
    
    if(Trigger.isInsert || Trigger.isUpdate){
        for(Task T: Trigger.new){
            set_id.add(T.WhatId);
            
        }
        
    }
    
    else if(Trigger.isDelete){
        for(Task T: Trigger.old){
            set_id.add(T.WhatId);
            
        }
        
    }
    
    if(Trigger.isAfter &&(Trigger.isInsert || trigger.isUpdate ||  Trigger.isDelete)){
        acc_list = [SELECT Id, Number_of_Tasks__c,(SELECT Id FROM Tasks WHERE Status = 'Completed' AND (CS_Activity__c = FALSE)) FROM Account WHERE Id IN: set_id];
        
        for(Account acc: acc_list){
            if(acc_list.size()>0)
                acc.Number_of_Tasks__c = acc.Tasks.size();
            else
                acc.Number_of_Tasks__c = 0;
        
    }
    
    if(!acc_list.isEmpty())
        update acc_list;

}

}
Hello,

I am looking to see if it is possible to create a Button on an object that when clicked it will direct to the most recent item in the recent items list in the side panel. Does anyone know if this is possible. Any help would be appreciated.

Thanks!
We have a custom object called employees, we have two specific date fields on each record the hire date and date no longer with the company. My question is it possible to create a report that shows how many people were hired and how may people are no longer with the company for any given month? It would look something like the below:
User-added image

Any help would be very beneficial. Thanks.
I stumbled accross the below formula while scanning through the community. It has worked very well for us but due to a change in the system we need to have it slightly changed.

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}

function appendTags(){
if(jQuery('[id=start-theme-css]').length==0){
jQuery('head').append(
'<link ' +
'id="start-theme-css"' +
'rel="stylesheet"' +
'href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.min.css"' +
'type="text/css" />'
);

jQuery('body').append(
'<div id="dialog-confirm" title="Quick Mass Mailer">' +
'<p style="text-align:justify">' +
'<img src="/s.gif" alt="Contact" class="pageTitleIcon" title="Contact" style="margin: 0 7px 30px 0"/>' +
'Please select an email template to use. To create a new template, you must exit this mass email process and create the new template in your personal setup section.' +
'<br/><br/>Email Template:<br/>' +
'<select id="email-template" style="width:380px"></select>' +
'</p>' +
'</div>'
);
}
}

function createPopupWindow(){
jQuery(function() {
jQuery( "#dialog-confirm" ).dialog({
resizable: false,
width: 400,
modal: true,
show: {
effect: "bounce",
duration: 500
},
hide: {
effect: "bounce",
duration: 500
},
buttons: {
"Send Mail":
function() {
sendMail();
},

Cancel:
function() {
jQuery( this ).dialog( "close" );
}
}
});
});
}

function fetchEmailTemplates(){
var emailTemplates =
sforce.connection.query(
'SELECT Id, Name FROM EmailTemplate',
{
onSuccess:
function(result){
var records = result.getArray('records');
var innerHtml = '<option value="">--Select--</option>';
for(var i=0; i<records.length; i++)
innerHtml +=
'<option value="' + records[i].Id + '">' +
records[i].Name +
'</option>';

jQuery('[id=email-template]').html(innerHtml);
},
onFailure:
function(error){
alert('An Error has Occurred. Error: ' + error);
}
}
);
}

function sendMail(){
var contactIds = {!GETRECORDIDS( $ObjectType.Contact )};
var templateId = jQuery('[id=email-template]').val();
if(contactIds.length>0 && templateId!=''){
var massMailRequest = new sforce.MassEmailMessage();
massMailRequest.targetObjectIds = contactIds;
massMailRequest.templateId = templateId;
massMailRequest.replyTo = 'noreply@salesforce.com';

sforce.connection.sendEmail([massMailRequest]);

alert('Your emails have been submitted for processing.');
}
}

appendTags();
fetchEmailTemplates();
createPopupWindow();


We are going to be linking the contact via look up to a custom object in salesforce and we will then have the custom object related list on the record. We would like  to be able to send the contacts a mass emailer through the custom object. I have tried to manipulate the code to allow this but cannot seem to figurre it out. Would anyone be able to assist?

Is it possible to bring over Asset Information that has been placed on a Lead when we convert the Lead to an Account? We currently have it setup that when an Asset is created on a lead the Assets as always assigned to a specific Account just for Leads with Assets. What we would like is for when it comes time for the Lead to be converted that a trigger is in place to remove the text in the Account field and replace it with the Account ID of the converted lead. Is this doable? If so would someone be willing to help me out?
I am trying to develop a visualforce page that allows a user to see the Companies Website without having to leave the Account page. Is this possible?
Hello,

Below are a trigger and its test class. Understanding that the coverage needs to be 75% in order to send it to production, I seem to be stuck with my code, and I am hoping that someone may be able to push me in the right direction.


trigger updatezipcode on Account (before update, before insert) {
    List<String> BillingPostalCodes = new List<String>();
   
    for (Account a:Trigger.new){
        BillingPostalCodes.add(a.BillingPostalCode.substring(0,5));
    }

    List <Zip_Code__c> ZipCodeList = [Select ID, Name from Zip_Code__c where Name in :BillingPostalCodes];

    for (Integer i = 0; i <Trigger.new.size(); i++){
        if (ZipCodeList.size() > 0 && Trigger.new[i].BillingPostalCode.substring(0,5) !=null){
                        for (Zip_Code__c z:ZipCodeList){
                if (Trigger.new[i].BillingPostalCode.substring(0,5) == z.name){
                        Trigger.new[i].Zip_Code_Territory__c = z.ID;

                                }
                        }
        }
        else{
        Trigger.new[i].Zip_Code_Territory__c = null;
        }
       
    }
}

@isTest
private class TestZip {
    static testMethod void testZipChange() {
        Account[] Accounttest = new Account[]{
         new Account(Name ='Tester1', BillingPostalCode = '44281'),
         new Account(Name ='Tester2', BillingPostalCode = '44282'),
         new Account(Name ='Tester3', BillingPostalCode = '44283'),
         new Account(Name ='Tester4', BillingPostalCode = '44284'),
         new Account(Name ='Tester5', BillingPostalCode = '44285'),
         new Account(Name ='Tester6', BillingPostalCode = '44286',OwnerId = '005C0000006nFc6')
         };
         insert Accounttest;
           
        Test.startTest();
        Accounttest[0].BillingPostalCode = '44281';
        update Accounttest;
        Test.stopTest();
       
        Accounttest = [SELECT id, BillingPostalCode, Zip_Code_Territory__c FROM Account WHERE id IN:Accounttest];


    }
}

The bolded area in the trigger is what is not covered in the class. 

Thank you for any help!
I am hoping someone can help me out with this, I have a custom object called Zip Code and it stores all Zip Codes within the United States. I would like to create a trigger that takes the first 5 digits of a US zip code and places it in a lookup field matching that 5 digit billing zip code.

I do not really have much knowledge with apex and was hoping someone would be able to point me in the right direction or possibly someone has already accomplished this sames situation.

Thank you for your help!
I am trying to develop a visualforce page that allows a user to see the Companies Website without having to leave the Account page. Is this possible?
Hello,

Below are a trigger and its test class. Understanding that the coverage needs to be 75% in order to send it to production, I seem to be stuck with my code, and I am hoping that someone may be able to push me in the right direction.


trigger updatezipcode on Account (before update, before insert) {
    List<String> BillingPostalCodes = new List<String>();
   
    for (Account a:Trigger.new){
        BillingPostalCodes.add(a.BillingPostalCode.substring(0,5));
    }

    List <Zip_Code__c> ZipCodeList = [Select ID, Name from Zip_Code__c where Name in :BillingPostalCodes];

    for (Integer i = 0; i <Trigger.new.size(); i++){
        if (ZipCodeList.size() > 0 && Trigger.new[i].BillingPostalCode.substring(0,5) !=null){
                        for (Zip_Code__c z:ZipCodeList){
                if (Trigger.new[i].BillingPostalCode.substring(0,5) == z.name){
                        Trigger.new[i].Zip_Code_Territory__c = z.ID;

                                }
                        }
        }
        else{
        Trigger.new[i].Zip_Code_Territory__c = null;
        }
       
    }
}

@isTest
private class TestZip {
    static testMethod void testZipChange() {
        Account[] Accounttest = new Account[]{
         new Account(Name ='Tester1', BillingPostalCode = '44281'),
         new Account(Name ='Tester2', BillingPostalCode = '44282'),
         new Account(Name ='Tester3', BillingPostalCode = '44283'),
         new Account(Name ='Tester4', BillingPostalCode = '44284'),
         new Account(Name ='Tester5', BillingPostalCode = '44285'),
         new Account(Name ='Tester6', BillingPostalCode = '44286',OwnerId = '005C0000006nFc6')
         };
         insert Accounttest;
           
        Test.startTest();
        Accounttest[0].BillingPostalCode = '44281';
        update Accounttest;
        Test.stopTest();
       
        Accounttest = [SELECT id, BillingPostalCode, Zip_Code_Territory__c FROM Account WHERE id IN:Accounttest];


    }
}

The bolded area in the trigger is what is not covered in the class. 

Thank you for any help!
I am hoping someone can help me out with this, I have a custom object called Zip Code and it stores all Zip Codes within the United States. I would like to create a trigger that takes the first 5 digits of a US zip code and places it in a lookup field matching that 5 digit billing zip code.

I do not really have much knowledge with apex and was hoping someone would be able to point me in the right direction or possibly someone has already accomplished this sames situation.

Thank you for your help!