• Craig Phoenix
  • NEWBIE
  • 90 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 7
    Questions
  • 14
    Replies
Hello,

I have wrtitten a triger like below:

trigger contractAfterInsert on Contract (after insert) {   

When i create new contract, the trigger is never executed, i cecked in prespective analysis, only the validation rule and wrkflow is executed

any idea on reason ?
  • September 20, 2019
  • Like
  • 0
I have a Process builder setup where when our Marketing integration creates the campaign member record it updates the Lead with the name of the campaign however when sales manually press the "Add to Campaign" button on the "Campaign History" related history it does not trigger this same process as the field is not updated.

Do I need to adjust any code or create a new process to copy the campaign name to the Latest Campaign name field?
I am wanting a checkbox formula to checkmark when the record CreatedDate is either Saturday or Sunday (Weekend).

I have tried searching around however all I am finding is comparing two dates and not counting weekend days which is not what I am needed.

Any help would be appreciated!
Hi,

I am building and working on an Apex Batch Class and almost got it built but for some reason I am not able to resove an error on line 4 and I am hoping someone can help me understand the error and help me with adjusting as needed?
 
global class LeadDailyUpdater implements Database.Batchable<sObject>{
    
    global Database.QueryLocator start(Database.BatchableContext bc){
    	return Database.getQueryLocator [select id, LastModifiedDate, Status, leadsource from Lead Where LastModifiedDate < LAST_N_DAYS:30];
    }
    
    global void execute(Database.BatchableContext bc,List<lead> scope)
    {
        List<Lead> leads=new List<Lead>();
        for(lead l : scope)
        {
            l.LeadSource='Closed';
            leads.add(l);
        }
        update leads;
    }
    
    global void finish(Database.BatchableContext bc)
    {
      AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :bc.getJobId()];
        system.debug(job);
    }     
}

The only item that is throwing an error is line 4 which I highlighted in code above (line where starts return Data base.getQueryLocator...

Effectively I am looking to pull all leads with last modified date greater than 30 days then update the status to Closed.
I am struggling with building a trigger to create a case when Opportunity is Closed with Setup Needed = Yes (Picklist) and still trying to learn as I run with Apex.

Opportunity fields Stage=Closed Won, Type=Upgrade and Setup Needed=Yes once all 3 of these fields are set to these values I need it to create a Case with Subject containing Opportunity Name and Account Name, also link to Account that is attached to the Opportunity then dump a bunch of the Opportunity fields into the Description field for example:
Customer: {!Account.Name}
AccountNumber: {!Account.AccountNumber__c}
Sold By: {!Opportunity.OwnerFullName}

I had it setup (since minimal coding experience) where it used a workflow to send an email which looped back into SF with Email-to-Case but thats not working 100% so I believe I need to move it into SF directly.

If anyone can help with building the trigger to create the case with field data from the Opp passed into the case that would be great help!
I have a trigger that is effectively checking a custom list to match the Close Date with the Start/End dates for weeks so a custom field is populated with the text of the Start and End dates.

Trigger:
trigger CloseWeekUpdate on Opportunity (before insert, before update) {
    Try{
        for(Opportunity opp : trigger.new){
            if(opp.CloseDate != NULL){
                system.debug('opp.CloseDate = ' + opp.CloseDate);
                for(CloseDateWeek__c rec : CloseDateWeek__c.getAll().values()){
                    if (opp.CloseDate >= rec.WeekStartDate__c && opp.CloseDate <= rec.WeekEndDate__c){
                        system.debug('rec.WeekStartDate__c = ' + rec.WeekStartDate__c);
                        system.debug('rec.WeeEndDate__c = ' + rec.WeekEndDate__c);
                        opp.Close_Week__c = rec.WeekStartDate__c.format() + ' - ' + rec.WeekEndDate__c.format();
                        system.debug('rec.Close_Week__c = ' + opp.Close_Week__c);
                        break;
                    }
                }
            }
        }
    }
    Catch(Exception Ex){
        system.debug('Exception Details = ' + Ex);
    }


I have built a test class to insert a test Opportunity and I am getting to 50% but unable to get higher, how do I get the class to test the following lines from the Trigger?

Lines that are not testing:

- for(CloseDateWeek__c rec : CloseDateWeek__c.getAll().values()){
- if (opp.CloseDate >= rec.WeekStartDate__c && opp.CloseDate <= rec.WeekEndDate__c){
- opp.Close_Week__c = rec.WeekStartDate__c.format() + ' - ' + rec.WeekEndDate__c.format();

Here is the Test class I have:
@isTest
    public class TestCloseWeekUpdate {
        static testMethod void testCloseWeek(){
            Opportunity to = new Opportunity();
            to.Name = 'Test Name';
            to.CloseDate = Date.newInstance(2020,06,06);
            to.StageName = 'Closed Won';
            to.Start_Date__c = Date.newInstance(2020,06,01);
            to.Type = 'New Business';
            to.Market__c = 'Large';
            to.Premium__c = TRUE;
            to.Startup_Needed__c = 'Yes';
            insert to;
            test.startTest();
            try{
                to.Close_Week__c = '5/31/2020 - 6/6/2020';
            }
            Catch (Exception ee){}
            test.stopTest();
        }
    }


Any help with getting that last 3 lines covered is greatly appreciated! 
I have created a trigger to run before insert to send an alert when cases reach 5 within 60 minutes of the most recent case.

Code:
trigger OutageAlert on Case (before insert) {
    date today =system.today();
    List<Case> numberofcases = [SELECT ID FROM CASE where SLA__c<=:1];
        for(case cas:trigger.new){
            if(cas.origin == 'Web - Email'){
                if(numberofcases.size() == 5) {
                    cas.SendAlert__c = true;
                }
            }
        }
}

I am wondering now how I can have this code ONLY run outside of business hours? for example how could I have this only perform the action to mark SendAlert__c = True IF it is between 17:00-06:00 Monday to Friday and all day/night Saturday and Sunday?

Is it possible to have it limited to only occur during none business times?
Hello,

I have spent time reviewing multiple questions and trying to built on my own but due to just starting out with development in Salesforce my knowledge is limit.

I found these two questions that closely mirror what my team needs (Send Email when cases hit certain criteria (https://developer.salesforce.com/forums?id=906F0000000kGjEIAU) and Email alert if number of opened cases reaches certain value (https://developer.salesforce.com/forums/?id=906F0000000AXeBIAW))

What I am needing to create is a system where either of the two items trigger an automated email to senior leadership
1 - Checks the current open cases within the last 60 minutes from when the program runs, so program runs every 30 minutes and looks back at the last 60 minutes to see if 10 or more cases were opened within the last 60 minutes.
2 - Every hour the program runs and looks back at the last hour and IF 10 or more cases opened it sends an email alert.

Any help is greatly appreciated.
I am wanting a checkbox formula to checkmark when the record CreatedDate is either Saturday or Sunday (Weekend).

I have tried searching around however all I am finding is comparing two dates and not counting weekend days which is not what I am needed.

Any help would be appreciated!
Hi all,
as we need a list view or a report showing cases in a specific status, say 'Waiting for feedback', how can we set a field with a date in order to track when a case goes to status 'Waiting for feedback' for the first time (since the creation of a case).
Would you use process builder for it or is there a possibility with a formula field?
Hi,

I am building and working on an Apex Batch Class and almost got it built but for some reason I am not able to resove an error on line 4 and I am hoping someone can help me understand the error and help me with adjusting as needed?
 
global class LeadDailyUpdater implements Database.Batchable<sObject>{
    
    global Database.QueryLocator start(Database.BatchableContext bc){
    	return Database.getQueryLocator [select id, LastModifiedDate, Status, leadsource from Lead Where LastModifiedDate < LAST_N_DAYS:30];
    }
    
    global void execute(Database.BatchableContext bc,List<lead> scope)
    {
        List<Lead> leads=new List<Lead>();
        for(lead l : scope)
        {
            l.LeadSource='Closed';
            leads.add(l);
        }
        update leads;
    }
    
    global void finish(Database.BatchableContext bc)
    {
      AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :bc.getJobId()];
        system.debug(job);
    }     
}

The only item that is throwing an error is line 4 which I highlighted in code above (line where starts return Data base.getQueryLocator...

Effectively I am looking to pull all leads with last modified date greater than 30 days then update the status to Closed.
I am struggling with building a trigger to create a case when Opportunity is Closed with Setup Needed = Yes (Picklist) and still trying to learn as I run with Apex.

Opportunity fields Stage=Closed Won, Type=Upgrade and Setup Needed=Yes once all 3 of these fields are set to these values I need it to create a Case with Subject containing Opportunity Name and Account Name, also link to Account that is attached to the Opportunity then dump a bunch of the Opportunity fields into the Description field for example:
Customer: {!Account.Name}
AccountNumber: {!Account.AccountNumber__c}
Sold By: {!Opportunity.OwnerFullName}

I had it setup (since minimal coding experience) where it used a workflow to send an email which looped back into SF with Email-to-Case but thats not working 100% so I believe I need to move it into SF directly.

If anyone can help with building the trigger to create the case with field data from the Opp passed into the case that would be great help!
I have a trigger that is effectively checking a custom list to match the Close Date with the Start/End dates for weeks so a custom field is populated with the text of the Start and End dates.

Trigger:
trigger CloseWeekUpdate on Opportunity (before insert, before update) {
    Try{
        for(Opportunity opp : trigger.new){
            if(opp.CloseDate != NULL){
                system.debug('opp.CloseDate = ' + opp.CloseDate);
                for(CloseDateWeek__c rec : CloseDateWeek__c.getAll().values()){
                    if (opp.CloseDate >= rec.WeekStartDate__c && opp.CloseDate <= rec.WeekEndDate__c){
                        system.debug('rec.WeekStartDate__c = ' + rec.WeekStartDate__c);
                        system.debug('rec.WeeEndDate__c = ' + rec.WeekEndDate__c);
                        opp.Close_Week__c = rec.WeekStartDate__c.format() + ' - ' + rec.WeekEndDate__c.format();
                        system.debug('rec.Close_Week__c = ' + opp.Close_Week__c);
                        break;
                    }
                }
            }
        }
    }
    Catch(Exception Ex){
        system.debug('Exception Details = ' + Ex);
    }


I have built a test class to insert a test Opportunity and I am getting to 50% but unable to get higher, how do I get the class to test the following lines from the Trigger?

Lines that are not testing:

- for(CloseDateWeek__c rec : CloseDateWeek__c.getAll().values()){
- if (opp.CloseDate >= rec.WeekStartDate__c && opp.CloseDate <= rec.WeekEndDate__c){
- opp.Close_Week__c = rec.WeekStartDate__c.format() + ' - ' + rec.WeekEndDate__c.format();

Here is the Test class I have:
@isTest
    public class TestCloseWeekUpdate {
        static testMethod void testCloseWeek(){
            Opportunity to = new Opportunity();
            to.Name = 'Test Name';
            to.CloseDate = Date.newInstance(2020,06,06);
            to.StageName = 'Closed Won';
            to.Start_Date__c = Date.newInstance(2020,06,01);
            to.Type = 'New Business';
            to.Market__c = 'Large';
            to.Premium__c = TRUE;
            to.Startup_Needed__c = 'Yes';
            insert to;
            test.startTest();
            try{
                to.Close_Week__c = '5/31/2020 - 6/6/2020';
            }
            Catch (Exception ee){}
            test.stopTest();
        }
    }


Any help with getting that last 3 lines covered is greatly appreciated! 
Hello,

I have wrtitten a triger like below:

trigger contractAfterInsert on Contract (after insert) {   

When i create new contract, the trigger is never executed, i cecked in prespective analysis, only the validation rule and wrkflow is executed

any idea on reason ?
  • September 20, 2019
  • Like
  • 0

Hi all, straight to the point. I am a php and javascript developer with 10+ years in the field. I was asked as a favor to do some work for a company using salesforce.

I created a developers account, learned and figured out how to write the apex classes, visualforce pages, and custom objects needed to accomplish what I was asked to do.

There is a drupal install on a website I own, that acts as an intermideary between salesforce and twilio sms services, and mailchimp email service.
EVERYTHING works, I have completed the job, if the company I did this for used my developer account. Obviously thats not an option, and I am having one hell of a time finding the proper way to migrate/deploy all the apex classes, custom visualforce pages, and custom objects to the group edition account of the prinicipal company
 

PLEASE, ive spent 15+ hours working thru examples, running into walls, finding many non-working answers.. Someone please point me in the right direction here.

 

Thank you!

Jason

I have created a trigger to run before insert to send an alert when cases reach 5 within 60 minutes of the most recent case.

Code:
trigger OutageAlert on Case (before insert) {
    date today =system.today();
    List<Case> numberofcases = [SELECT ID FROM CASE where SLA__c<=:1];
        for(case cas:trigger.new){
            if(cas.origin == 'Web - Email'){
                if(numberofcases.size() == 5) {
                    cas.SendAlert__c = true;
                }
            }
        }
}

I am wondering now how I can have this code ONLY run outside of business hours? for example how could I have this only perform the action to mark SendAlert__c = True IF it is between 17:00-06:00 Monday to Friday and all day/night Saturday and Sunday?

Is it possible to have it limited to only occur during none business times?
Hello,

I have spent time reviewing multiple questions and trying to built on my own but due to just starting out with development in Salesforce my knowledge is limit.

I found these two questions that closely mirror what my team needs (Send Email when cases hit certain criteria (https://developer.salesforce.com/forums?id=906F0000000kGjEIAU) and Email alert if number of opened cases reaches certain value (https://developer.salesforce.com/forums/?id=906F0000000AXeBIAW))

What I am needing to create is a system where either of the two items trigger an automated email to senior leadership
1 - Checks the current open cases within the last 60 minutes from when the program runs, so program runs every 30 minutes and looks back at the last 60 minutes to see if 10 or more cases were opened within the last 60 minutes.
2 - Every hour the program runs and looks back at the last hour and IF 10 or more cases opened it sends an email alert.

Any help is greatly appreciated.

Hello all,

So I created a trigger to Cases in a queue, when size is reached I want to send an email once..only once.

My trigger is firing at limit (3), but is sending the email 3 times. I think I need a second or third set of eyes to see what I am missing.

Thanks for your help.

Robert 

trigger NotificationExceedingQueueLimit3 on Case (before insert,before update) {

boolean EmailSent = False;

    list<group> queuelist= [SELECT id  FROM Group where DeveloperName = 'CPS_Default_Queue'and Type = 'Queue' limit 1];     
    if(queuelist.size()>0){
                
             list<case> caselist = [select id from case where ownerid =:queuelist[0].id];
             for(case cs : trigger.new){
             
                if(caselist.size()==3 && EmailSent == False)
                {
                  EmailSent = True; 
                  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  List<String> sendTo = new List<String>();
                  sendTo.add('Hello.Friend@gmail.com' );
                  mail.setHtmlBody('Hello, <br/> Default Queue Limit Exceeded. The count has exceeded 2 cases.<br/><br/> Thanks, <br/>Salesforce Admin');
                  mail.setSubject('Case Limit of 02 Exceeded');
                  mail.setToAddresses(sendTo);
                  mails.add(mail);   
                  Messaging.sendEmail(mails); 
                }
        
             }
    }  
}
 

 

 

I've seen a few companies using saleforce have a thumbs up/down icon to indicate if the response of the einstein chatbot was appropriate. How do I get that?