• champ_vimal
  • NEWBIE
  • 75 Points
  • Member since 2009

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 15
    Replies

Hi,

 

I have created some batch apex code alongwith other triggers and class/controller codes. 

 

When I run individual test methods on them, I am able to get test success result alongwith nice code coverage %. However when I run all tests together, I get following test failure errors:-

 

1)System.AsyncException: Database.executeBatch cannot be called from a batch or future method.

2)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

3)System.AsyncException: Future method cannot be called from a future method: getLead_Rollup_Amount(Id)

4)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

 

Please note again that the exceptions dont come when tested individually.

 

Please advise on same.

 

 

Thanks,

 

Vimal 

Hi,

 

I have a visualforce page which has a UserRole field which needs to be lookup.
However, I am using custom controller for same. Can you please let me know how can I display lookup field for same in my visualforce page?

 

 

Thanks,

 

Vimal 

Hello All,

 

I am writing a test method for a trigger and it gives me failure error during run test saying that there is some custom field validation exception. 

 

The exact failure message is : 

 

'System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Step 1 provider is tagged to this job centre: [Jobcentre_Plus__c]'

 

Please note there is no such validation rules in any of objects I have used in test method. But after going through some information from test method articles, I have even corporated  Dml Exception failure using try catch statements and that error disappears!

 

Now I have different error while running test. It gives me REQUIRED_FIELD_MISSING error at line 54 col 3 for Job_Seeker_Case__c field in Action Plan Object record insert even though I have given the value to it.

 

My questions are:

 

1) How can I fix my code?

2) What is the significance of CUSTOM FIELD VALIDATION error even if we have no validations on any of objects concerned?

 

Request you to please assist me in this!

 

Here is the code:-

 

public class testTrgActionAfterUpdateInsert
{
 static testMethod void trgActionAfterUpdateInsertMethod()
 {
  Jobcentre_Plus__c JCP = new Jobcentre_Plus__c(Phone__c='456676',Town_City__c='Mumbai', Street__c='420', region__c = 'Wales',Jobcentre_Plus_Office_Code__c='Off Code 1',JCP_Advisor_Name__c='Vimal Desai',Name = 'Job Centre 1', County__c='Maharashtra',Postcode__c='98765');
  try {
       insert JCP;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }

 
  Account JS = new Account(FirstName= 'Jose',LastName= 'Aquilani',NI_Number__c = 'JC522826C',Town_City__c='Mumbai', Street__c='200',County__c='Ker',Postcode__c='12141',Preferred_Method_of_Communication__c='Letter');
  //insert JS;
   try {
       insert JS;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }
 
  Date date1 =Date.newInstance(2009,08,12);
 
  Provider__c PRO = new Provider__c(name = 'Pro1', Contractor_No__c = 'Cr - 102', Contract_No__c = 'C - 102', Step__c = '2', Can_Claim__c = 'Yes', Type__c = 'tbc',  Street__c = 'Strt - 1', Town_City__c = 'Mumbai', County__c = 'County 1', Postcode__c = 'Post Code - 1', Main_Contact__c = JS.OwnerId);
  insert PRO;

  Job_Seeker_Case__c JSC =  new Job_Seeker_Case__c(Job_Seeker__c=JS.id,DWP_PO_No__c='Dwp-123',Jobcentre_Plus__c=JCP.id,Date_of_Referral__c=date1, Step_1_Provider__c = PRO.id);
  //insert JSC;
 
   try {
       insert JSC;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }

  Action_Plan__c actPlan = new Action_Plan__c(Action_Plan_Start_Date__c = date1, Status__c = 'In Progress', Frequency_of_Contact__c = 'Once a Week', Agreed_Number_of_Weekly_Job_Applications__c = 32, Job_Seeker_Case__c = JSC.id);
  insert actPlan;
 
  Action__c actn = new Action__c(Action_Plan__c = actPlan.id, Status__c = 'In Progress', Action_Owner__c = 'act own 1');
  insert actn;
 
  System.assertEquals(actPlan.Actions_Last_Updated_Date__c, System.Today());
 
 }
}

 

Thanks,

 

Vimal

 

 

Basicallly some kind of workflow or control that says if this check box is checked then make sure the address for this contact always matches the Account Billing addresss or whatever?

Hi,

 

I am getting an error : "Failed to send request to https://www.salesforce.com/services/Soap/u/15.0" while logging into Data Loader.

 

I have updated proxy settings(Server host: https://www.salesforce.com, proxy host entered etc) and also used security token alongwith normal Salesforce password. As last step, I uninstalled the data loader and installed it again. Still the same error.

 

Please assist!

 

Thanks,

 

Vimal

Hi,

 

I am having problems with System.assertEquals method not working in my test method. This is the trigger and the class with testmethod:-

 

 

trigger NoOfEmployeesTrigger on Account (before insert, before update) 
{
if(Trigger.isInsert)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}

if(Trigger.isUpdate)
{
Account[] accs = Trigger.new;
for(Integer i=0; i<accs.size(); i++)
{
if(accs[i].name.contains('19'))
{
accs[i].NumberOfEmployees = 25;
}
else
accs[i].NumberOfEmployees = 75;
}
}
}
 public class NoOfEmployeesClass
{
static testMethod void NoOfEmployeesTest()
{
Account acc1 = new Account(name = 'Vim_19Jun_acc1');
Account acc2 = new Account(name = 'Vim_20Jun_acc2');

test.startTest();
insert acc1;
insert acc2;

System.assertEquals(25, acc1.NumberOfEmployees);
//System.assertNotEquals(acc2.NumberOfEmployees, 25);

acc2.name = 'Vim_19Jun_acc2';
update acc2;

test.stopTest();
}
}

The Number of employees field is a number field and it is giving error there under Test failures section:-

 

Method Name
Total Time (ms)
Message
Stack Trace
NoOfEmployeesClass.NoOfEmployeesTest126.0System.Exception: Assertion Failed: Expected: 25, Actual: nullClass.NoOfEmployeesClass.NoOfEmployeesTest: line 12, column 3

 

 

However, if I remove the method the test method works successfully giving 100% code coverage.

 

Please assist!

 

Thanks,

 

Vimal

I want to create a roll-up summary field on the campaign object that totals opportunity values that meet certain criteria (date range of close date & Record Type).

 

I am at a loss. Any ideas? 

Hi All,

 

Can anyone please give me urls/links from where I can have different varieties of case studies/problems to practise on Salesforce functionalities like workflows, approvals, cases, tasks, rules, profiles, etc. Plus, if possible, I also need sample cases for Apex code development where I can try out practising myself the sample cases based on customizations.

 

(PS: I know about Force.com Cookbook, apart from this if we have anymore illustrations book, then I would be highly obliged.)

 

Thanks,

 

-Vimal

Hi,

 

I am trying to code down Apex script for the case when the account is of particular record type, insert and update some fields. I have done via hard coding record-type id field value and it succeeded in inserting and updating field values but still I want to generalise the code so that the same can be used in all sandboxes and organisations (I may be wrong but from what I have heard and learned, recrod type ids vary in sandbox and production environment for same record type, please let me know if I am wrong).

 

I have attempted to write the code as shown below. But still it does not work as required(does not insert/update records as per condition of Record Type name).

 

trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update)
{
   List<Id> AccIds = new List<Id>();
   String Flag;
 if(Trigger.isInsert)
 {
   Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
   Account[] newAccs = Trigger.new;
   for(Integer i=0; i < newAccs.size(); i++)
   {
    if(Trigger.new[i].RecordTypeId == RecId)
   //for(Account newAccs : Trigger.new)
    {
        // if(newAccs.RecordTypeId == '01290000000ChWo')
        //
          newAccs[i].Website = 'http://www.tcs.com';
          newAccs[i].BillingStreet = 'Yantra Park';
          //a.BillingCity = 'Mumbai';
          newAccs[i].BillingState = 'Maharashtra';
          newAccs[i].BillingCountry = 'India';
          newAccs[i].Fax = '223120';
          newAccs[i].Phone = '2230175';
          Flag = 'Y';
          AccIds.add(newAccs[i].Id);
  }
 }
 if(Flag == 'Y')
{
 Account[] accs = [select Id, name from Account where Id in :AccIds];
 insert accs;
}
}

if(Trigger.isUpdate)
{
 Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
   Account[] oldAccs = Trigger.new;
   for(Integer i=0; i < oldAccs.size(); i++)
   {
    if(Trigger.new[i].RecordTypeId == RecId)
   //for(Account newAccs : Trigger.new)
    {
        // if(newAccs.RecordTypeId == '01290000000ChWo')
        //
          oldAccs[i].Website = 'http://www.tcs.com';
          oldAccs[i].BillingStreet = 'Yantra Park';
          //a.BillingCity = 'Mumbai';
          oldAccs[i].BillingState = 'Maharashtra';
          oldAccs[i].BillingCountry = 'India';
          oldAccs[i].Fax = '223120';
          oldAccs[i].Phone = '2230175';
          Flag = 'Y';
          AccIds.add(oldAccs[i].Id);
    }
   }
   if(Flag == 'Y')
{
 Account[] accs = [select Id, name from Account where Id in :AccIds];
 update accs;
}}

}

Hi,

 

I am creating an apex trigger which triggers auto population of fields in Account with values based on a particular record type name. However, on saving the trigger it gives no errors neither while testing it on Salesforce. However, ofcourse, the records dont get updated with the values on condition of matching record type. Let me know where am I going wrong in the code below. Please suggest corrective actions accordingly.

 

Thanks,

 

Vimal

 

trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update) 
{
 if(Trigger.isInsert)
 {
  Account[] newAccs = Trigger.new;
  RecordType rt1 = [select name from RecordType where SobjectType = 'Account' limit 1];
  if(rt1.name == 'rec_type1') 
  {
   for (Account a:newAccs)
   {
    a.Website = 'http://www.tcs.com';
    a.BillingStreet = 'Yantra Park';
    a.BillingCity = 'Mumbai';
    a.BillingState = 'Maharashtra';
    a.BillingCountry = 'India';
    a.Fax = '223120';
    a.Phone = '2230175';
   }
   insert newAccs;
  }
 }
 if(Trigger.isUpdate)
 {
  Account[] oldAccs = Trigger.new;
  RecordType rt2 = [select name from RecordType where SobjectType = 'Account' limit 1];
   //if (a.RecordType.Name == 'rec_type1') 
   //if(a.Industry == 'Technology')
  if(rt2.name == 'rec_type1')
  {
  for (Account a:oldAccs)
   {
    a.Website = 'http://www.tcs.com';
    a.BillingStreet = 'Yantra Park';
    a.BillingCity = 'Mumbai';
    a.BillingState = 'Maharashtra';
    a.BillingCountry = 'India';
    a.Fax = '223120';
    a.Phone = '2230175';
   }
   update oldAccs;
  }
 }
}
I am wondering how do static variables behave in Salesforce. Is the variable shared by all the threads/users within an org?

In the following example, p.FirstRun is set to false inside the trigger.

What happens when :

1. At the same time user 1 is executing this trigger, user 2 is also executing the same trigger? Do they overwrite each other's value?
2. What happens  when 10 minutes later someone else needs to execute the same trigger. Is the p.FirstRun set to false by the the first
    execution of the trigger? Does the trigger below need to reset p.FirstRun to true when it comes back in the second time for recursion so that a second user
    ten minutes later find p.Firstrun as true?
 


Code:

From Salesforce Apex Language reference manual:

Use static variables to store information that is shared within the confines of the class. All instances of the same class share a
single copy of the static variables. For example, all triggers that are spawned by the same request can communicate with each
other by viewing and updating static variables in a related class. A recursive trigger might use the value of a class variable to
determine when to exit the recursion.

A trigger that uses this class could then selectively fail the first run of the trigger:

Suppose you had the following class:
     public class p {
    public static boolean firstRun = true;
}

trigger t1 on Account (before delete, after delete, after undelete) {
if(Trigger.isBefore){
     if(Trigger.isDelete){
           if(p.firstRun){
              Trigger.old[0].addError('Before Account Delete Error');
               p.firstRun=false;
          }
    }
 }
}