• Aubry
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 13
    Replies
Here is the Apex Class
public class AssignLeadsUsingAssignmentRules
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Lead Leads=[select id,OwnerId from lead where lead.id in :LeadIds];
            Leads.setOptions(dmo);
        	system.debug('Before Update Lead Details' + Leads);
         	Database.update(Leads,dmo);
        	Lead Leads2=[select id,OwnerId from lead where lead.id in :LeadIds];
        	system.debug('After Update Lead Details' + Leads2);
   }
}

Here is the test class 
@isTest 
      public class TestAssignLeadsUsingAssignmentRules{
      static testMethod void createnewlead() {
     
   //   Test.startTest();    
      Lead leadToCreate =new Lead();
      List<id> Ids= New List<Id>();
    //  leadToCreate.ownerid= userToCreate.id;
      leadToCreate.ownerid= UserInfo.getUserId();  
      leadToCreate.LastName ='Sample1';
      leadToCreate.Email='Someone@somewhere.com';
      leadToCreate.Company='OneTwo34';
      leadToCreate.LeadSource='Partner Referral';
      leadToCreate.Country='IN';
      leadToCreate.Source_Last_Lead_Source_Detail__c='Form - Contact Form';
          
      insert leadToCreate; 
      
      Ids.add(leadToCreate.id);
      AssignLeadsUsingAssignmentRules.leadAssign(Ids);
      System.assertEquals('00G1W000002RyhMUAS', leadToCreate.OwnerId, 'Something is wrong');

 	//  Test.stopTest();
      
   }
}

The test class fails as shown below User-added imageAs you can see the debug log shows the lead OwnerId has changed but the change does not persist outside the class in the test. What am I missing? 
We currently track cases in salesforce.com via our community. However, we do not store any of the consumer's data (Contacts, Accounts) in salesforce. We onlys create the case record along with name and email (Custome fields) of the person submitting the case via community. 

I would like to create a custom lightning component that will allow me to view all related cases based on a particular email. For example, below is a screenshot of a particular  case record in the Service Console,i would like to be able to build a lightning component next to the "Email Us" tab that shows all cases related to this email address. 

Greatly appreciate any guidance you can provide. 

User-added image
Hi Developers,
Iam learning salesforce customization part here i tried to create trigger to prevent duplicate entry of records while inserting and updating but i think iam missing somewhere. please review my code and help me to learn best coding practices.
Thanks in advance.
hereis my code

trigger PreventDuplicates on City__c (before insert,before update) {
list<City__c> lst = new list<City__c>(trigger.new);
list<City__c> lstcity =[select name from City__c where name in :lst.name];
if(lstcity.size>0){
for(City__c c: lst){

c.adderror('Duplicate records found');
}
}
}
Hello,

I am new to APEX so thanks in advance for helping a newbie out.

I need an APEX to run at midnight (I will use the SF scheduler) to update a custom field (whatever__c) with a number (42). My end goal is to have this field update (whatever__c = 42) will kickoff a process I created in process builder. 

Thanks again everyone 
Is it possible to schedule a job from a scheduled job? I tried this but kept getting the "The Apex job is already scheduled for execution".
Here is the Apex Class
public class AssignLeadsUsingAssignmentRules
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Lead Leads=[select id,OwnerId from lead where lead.id in :LeadIds];
            Leads.setOptions(dmo);
        	system.debug('Before Update Lead Details' + Leads);
         	Database.update(Leads,dmo);
        	Lead Leads2=[select id,OwnerId from lead where lead.id in :LeadIds];
        	system.debug('After Update Lead Details' + Leads2);
   }
}

Here is the test class 
@isTest 
      public class TestAssignLeadsUsingAssignmentRules{
      static testMethod void createnewlead() {
     
   //   Test.startTest();    
      Lead leadToCreate =new Lead();
      List<id> Ids= New List<Id>();
    //  leadToCreate.ownerid= userToCreate.id;
      leadToCreate.ownerid= UserInfo.getUserId();  
      leadToCreate.LastName ='Sample1';
      leadToCreate.Email='Someone@somewhere.com';
      leadToCreate.Company='OneTwo34';
      leadToCreate.LeadSource='Partner Referral';
      leadToCreate.Country='IN';
      leadToCreate.Source_Last_Lead_Source_Detail__c='Form - Contact Form';
          
      insert leadToCreate; 
      
      Ids.add(leadToCreate.id);
      AssignLeadsUsingAssignmentRules.leadAssign(Ids);
      System.assertEquals('00G1W000002RyhMUAS', leadToCreate.OwnerId, 'Something is wrong');

 	//  Test.stopTest();
      
   }
}

The test class fails as shown below User-added imageAs you can see the debug log shows the lead OwnerId has changed but the change does not persist outside the class in the test. What am I missing? 
Below Code Is Working For Insert Operation, Now I Need Max Number In the Case of Delete Operation How Can Get?


trigger SkillGroup_With_High_Rank on Skill_Group__c (after insert,before delete) {
        List<Id> AccnId = New List<Id>();
    public String Maxno;
   
    for(Skill_Group__c sk:Trigger.New){
        
        AccnId.add(sk.Account_Name__c); 
        system.debug('Accountssss'+AccnId);
    }
    list<aggregateResult> aggResults = [Select Max(Rank__c)RA from Skill_Group__c Where Account_Name__c In:AccnId ];
    
      system.debug('@@@@@@'+aggResults[0].get('RA'));
   Maxno = string.valueOf(aggResults[0].get('RA'));
    system.debug('$$$$$$$'+Maxno);
    for(Account ac: [Select id,Skill__c from Account where id In:AccnId]){
        ac.Skill__c = Maxno; 
    }
    }
In my org call is child object of account object. I need to count all call records and distinct(accounts) in call object. Call object may have more than 50000 records. Is there a way to achieve this?
If Email Deliverability is not set to All Email in my sandbox my code will error out when trying to send an email.  How can I check if Email Deliverabitlity is set to All Email in Apex so that I don't receive the NO_MASS_MAIL_PERMISSION errors?

I am trying to deploy one class which has implemented Schedulable interface.

But when I try to deploy it using ANT I am getting the following error :

"Schedulable class has jobs pending or in progress".

 

I am waiting for this to get resolved since more than 48 hrs and it doesn't seem to resolve.

What can be done in such case? How to deploy it to production? I tried to deploy by making packages but could not since the components in the package already exist in production and gives an error when I unzip the package. Please suggest what can be done in this situation.

  • March 26, 2010
  • Like
  • 0

I need to add essentially add a few values that are 'singletons'. I could create a custom object and use validation to ensure it was a singleton.

 

But is there a better way?

 

  • March 05, 2009
  • Like
  • 0