• vikas malik
  • NEWBIE
  • 220 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 0
    Replies
Need help with a test class as I am still a newbie at APEX coding....

I have the following trigger>>

trigger CaseTriggers on Case (after insert, before update) {
   
    if(trigger.isInsert){
        list<Lead> ldlist = new List<Lead>();
        for(case cse : trigger.new){
            if((cse.Assigned_To__c == null || cse.Assigned_To__c  == '') && cse.CLASS_Application_Status__c == '0-Pending Incomplete'){
                Lead ld = new Lead();
                ld.FirstName = cse.Applicant_First_Name__c;
                ld.LastName = cse.Applicant_Last_Name__c;
                ld.Phone = cse.Applicant_Primary_Phone__c;
                //if(cse.Applicant_Primary_Phone__c != null)
                    //ld.Phone = '('+cse.Applicant_Primary_Phone__c.substring(0, 3) + ') ' +cse.Applicant_Primary_Phone__c.substring(3, 6) + '-' +
cse.Applicant_Primary_Phone__c.substring(6, 10);
                ld.Email = cse.Applicant_Email__c;
                ld.Company = 'SpringLeaf Financial';
                ld.State = cse.Applicant_State__c;
                ld.CLASS_Lead_Source__c = cse.CLASS_Lead_Source__c;
                ld.Have_Auto_Approval_Flag__c = cse.Have_Auto_Approval_Flag__c;             
                if( cse.Time_Zone__c == 'EST')                   
                    ld.LiveOpsApp__Lead_Timezone__c = '(GMT-05:00) Eastern Standard Time (America/New_York)';
                if( cse.Time_Zone__c == 'CST')                   
                    ld.LiveOpsApp__Lead_Timezone__c = '(GMT-06:00) Central Standard Time (America/Chicago)';               
                if( cse.Time_Zone__c == 'MST')                   
                     ld.LiveOpsApp__Lead_Timezone__c = '(GMT-07:00) Mountain Standard Time (America/Denver)';
                if( cse.Time_Zone__c == 'PST')                   
                     ld.LiveOpsApp__Lead_Timezone__c = '(GMT-08:00) Pacific Standard Time (America/Los_Angeles)';
                ldlist.add(ld);              
            }
           
        }  
    if(ldlist.size()>0)
        insert ldlist;


I created a test class that when run is not even updating the Code Coverage.... It appears like the test class is not even testing. HELP..what I am doing wrong!

 

@isTest
private class testlead {

static testMethod void  insertNewLead() {
      
Lead ld = new Lead();
       ld.FirstName = 'David';
       ld.LastName  = 'Liu';
       ld.phone = '5555551236';
       ld.Email  = 'simon.williams@google.com';
       ld.Company = 'Dalfie';
       ld.State = 'IN';
       ld.CLASS_Lead_Source__c ='R2D2';
        if( cse.Time_Zone__c == 'EST')                   
                    ld.LiveOpsApp__Lead_Timezone__c = '(GMT-05:00) Eastern Standard Time (America/New_York)';
                if( cse.Time_Zone__c == 'CST')                   
                    ld.LiveOpsApp__Lead_Timezone__c = '(GMT-06:00) Central Standard Time (America/Chicago)';               
                if( cse.Time_Zone__c == 'MST')                   
                     ld.LiveOpsApp__Lead_Timezone__c = '(GMT-07:00) Mountain Standard Time (America/Denver)';
                if( cse.Time_Zone__c == 'PST')                   
                     ld.LiveOpsApp__Lead_Timezone__c = '(GMT-08:00) Pacific Standard Time (America/Los_Angeles)';ld.LiveOpsApp__Lead_Timezone__c = 'TEST';
   
    insert ld;
    }
}
Hi

can anyone please help by giving step by step procedure to edit an apex trigger in production?

I have eclipse installed on my computer
Thanks in advance
Hi- I just want to delete the existing records in contructor itself. 
This code is working in action method but its not working in constructor, Please share me idea if any one have. 

List<Forecast_Revenue_Report__c> foreRevRepOutput = [SELECT Forecast_Amount__c, Forecast_Month__c, opp_id__c FROM Forecast_Revenue_Report__c WHERE opp_id__c = :this.oppId];
for(Forecast_Revenue_Report__c frDelete : foreRevRepOutput ) {
                    delete frDelete;
       }

Thanks,
here is my class..
@IsTest
public class TestrecordExt{
   
    static testMethod void TestEmp(){
   
        //test.startTest();
        List<employee__c> eList = new List<employee__c>();
        employee__c e = new employee__c();
        e.Name = 'test';
        e.Last_Name__c = 'test';
        e.Join_Date__c = Date.Today();
        e.City__c = 'test city';
        e.Phone__c = '123456';
        eList.add(e);
   
       
        e = new employee__c();
        e.Name = 'employee Name';
        e.Last_Name__c = 'emp Last Name';
        e.Join_Date__c = Date.Today();
        e.City__c = 'test city';
        e.Phone__c = '123456';
        eList.add(e);
       
        insert eList;
       
        recordExt r = new recordExt();
        r.saveEmp();
   
        //test.stopTest();
    }

}
public class AF_ScriptController {
 
    public String status {get;set;}
    public Lead_Object__c obj {get; set; }

   /**
   ** Constructor
   **/
   public AF_ScriptController (ApexPages.StandardController controller) {

      String newId = ApexPages.currentPage().getParameters().get('leadId');
      System.debug ('new Id *** :' + newId);

      if (newId != '') {

         obj = [Select Id,First_Name__c,Last_Name__c,Dealer_Type__c,Products_Dealership__c,F_I_Manager__c,Contracts_Electronically__c,Dealer_Track_RouteOne__c,What_percent_of_inventory_has_a_selling__c,What_percent_of_your_inventory_has_less__c,What_percent_of_your_inventory_is_newer__c,How_many_front_line_ready_units_do_you_c__c,What_are_your_average_monthly_used_vehic__c,Service_Department_on_site__c,Dealership_Retail__c,Dealership_Permanent_Building__c,Dealership_Payed__c,How_many_years_have_you_been_in_business__c,Leadstatus__c, test__c, Do_you_have_any_brokers_or_non_automotiv__c, salutation__c  from Lead_Object__c where id = :newId limit 1];

       
         if (obj.LeadStatus__c == 'Qualified' ) {
            System.debug ('Qualified *** : ' + status);
            status = System.Label.AF_QualifiedScript;
         }
         else {
            status = System.Label.AF_UnqualifiedScript;
            System.debug ('UnQualified *** :' + status);
         }
       
      }

   }

}



Thanks in Advance
List<Test_Object__c> testObject = new List<Test_Object__c>();
testObject = [SELECT Id, Field1__c, Field2__c FROM TestObject__c]
String FieldNameNeeded = 'Field1__c';
for (Test_Object__c test : testObject) {
    FieldValueNeeded = test.Field1__c; //hardcoded field name
}
I have to create a trigger that creates a task after an e-mail is sent from Activity History in a custom object. I am trying to use MyCustomObject__History but I'm getting the following error: SObject type does not allow triggers: MyCustomObject__History
I can't seem to update my trigger so that it only creates a ticket in Jira (webservice connector) when the case status equals "Escalated". Can someone help?

trigger SynchronizeWithJIRAIssue on Case (after insert) {
    system.debug('trigger!');
    //Identify profile name to be blocked from executing this trigger
    String JIRAAgentProfileName = 'JIRA Agent2';
    List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];

    //Check if specified Profile Name exist or not
    if(!p.isEmpty())
    {
        //Check if current user's profile is catergorized in the blocked profile
        if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
        {
            for (Case c : Trigger.new) {
                    system.debug('inside case ' + c.CaseNumber);
                    //Define parameters to be used in calling Apex Class
                    String jiraURL = 'http://xxxxxxx';
                    String systemId = '2';
                    String objectType ='Case';
                    String objectId = c.id;
                    String projectKey = 'xxx';
                    String issueType = 'xx';
               
                    System.debug('\n\n status is escalated');
                    //Execute the trigger
                    JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
             }
        }
    }
}
How to create a popup alert to custom object?
I'm trying to implement lead assignment based on zip codes, and I'm running into an error with the code. I set up a Zip Code custom object, Zip_Code__c, where the name is the zipcode. Both the custom object and the Lead object have a custom text field, CA_Territory__c (this is for California zip codes only). When the zip code on a lead is entered or edited, I want to pull the CA Territory value from the custom object into the lead field. This is the code:

trigger CATerritory on Lead (before insert, before update) { 
//get the first five digits of the PostalCode from the lead 
set<string> left5zips = new set<string>(); 
for (lead l: trigger.New) if (l.postalcode !=null) left5zips.add(l.postalcode.substring(0,5));

//if no zip listed on the lead 
if(left5zips.isEmpty()) lead.ca_territory__c='None'; 

//query the zip_code object to get the zipcode (Name) and zone from the zip code object 
map<string,string> zmap=new map<string,string>(); 
  for(Zip_Code__c z :
     [Select name, ca_territory__c from Zip_Code__c WHERE name IN :left5zips])
zmap.put (z.name, z.ca_territory__c);

for(lead l:trigger.new){ 
if(zmap.containskey(l.left5zips)) 
     l.ca_territory__c=zmap.get(l.left5zips); 

}
The error I am getting is 'Compile Error: Expression cannot be assigned at line -1 column -1'. This is my first attempt at a trigger, and it is based on other people's code, so I don't really know how to troubleshoot. Any ideas? Thanks!
So i have written a valdiation rule below as follows,

IF
(
AND
(
NOT(ISBLANK(SmartAuction_Number_of_Contracts__c)),
ISBLANK(Smartauction_Amount_of_Current_Exception__c)

), true, false
)


Its working fine , but another requirement is

Even if the value is "0"  for the field "Smartauction_Amount_of_Current_Exception__c"  also it should not save it should have a valid number apart from "0" 


Help me how to achieve this 
1) i am having a picklist field called as "Type__c" if the value of type is set to "Other Adjustment"  then i am having other 2 picklist fields like "Month__c" and "Year__c" should be mandatory


IF(
AND(
NOT(
ISPICKVAL(Type__c, 'Other Adjustment')),ISBLANK( ADR_Move_From_Month__c),ISBLANK( ADR_Move_From_Year__c)), true, false)
I have written some code - which sends an email and includes some of the field values for a new case, but it leaves off the lookup field values (in other words, when I reference the Account.BillingCity, Contact.Email, etc.), I get null values.

From what I can tell, it looks like lookup values are inserted on new record creation after the case is inserted (and after the "After Insert" triggers have fired - this is why I get null values when the fields are referenced in my sent email.
I need to list the names of reports from a specific folder in a select field. searched for it and found nothing about it