• Gaurav Nirwal
  • PRO
  • 2142 Points
  • Member since 2014
  • Software Developer
  • Briskminds Software Solutions

  • Chatter
    Feed
  • 79
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 0
    Questions
  • 585
    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 All,
We created a trigger for Chatter. When a post contains keyword ”legal', a new record under ChatterPost will be generated. We also created Test class but got error, please help, thank you so much.

Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId]: [ParentId]
Stack Trace Class.ChatterPostTest.insertNewChatterPostTest: line 9, column 1


@isTest
public class ChatterPostTest
{
    static testMethod void insertNewChatterPostTest()
    {
        Test.StartTest();
        FeedItem f = new FeedItem();
        f.Body = 'legal test';
        insert f;
        Test.StopTest();
        System.assertEquals ('legal test', f.body);
    }
}

TRIGGER:
Trigger ChatterKeywordLegal on FeedItem (after insert) {
    List<FeedItem> FeedItems = new List<FeedItem>();
   for (FeedItem f : Trigger.new) {
           if (f.body!=null &&   f.body.contains('legal' ) ) {
               ChatterPost__c C = new ChatterPost__c();
               c.Description__c = f.body;
                   
              insert C;
        }
    }
   }
HI Folks,

I have a scenario i.e, Whoever is created the record but that record users manager & system admin only edit the record based on Grade field. For this i implemented a validation, but its not working properly. So please suggest me.

AND(
OR(ISCHANGED( Grade_1__c ), ISCHANGED( Grade_2__c ), ISCHANGED( Grade_3__c )),
OR( $User.Id=$User.ManagerId )
)

Highly appreciated!!
Hi,

string namevf=name;

            For(Contact objContact:[SELECT  :namevf,id,MailingStreet,MailingCity,MailingCountry,MailingState FROM Contact])
            {
          
          //some code
            
            }

in the above code , I want to replace  ":namevf" with "name"(or any other API name) if I store the API name in another string variable ...
can any one help me on this......
In the code snippet below I am able to see the Contact ID in the variable advisorIDS.  What would I add to the code to see another field on the contact record?
Thanks in Advance

public void doAutoSubscribe(Map<Id, Contact> contactMap) {
    
        Set<ID> advisorIDs = contactMap.keySet();
        system.debug(' ADVISOR ID----- >' + advisorIds);       

}
Hello everyone,

I am trying to do some data manipulation over records in a list. I was able to correctly build my list but now I am stuck with the calculations that I want to see happen.

Let's say I have record 1 and record 2 in my list. I want to grab a field called meter readings on both record and subtract the value of record 2 from the value from record 1 to get the actual energy use.

record 1 energy use = record 1 meter reading - record 2 meter reading.

And obvisouly I would like to repeat that for every records in my list except for the last one (since I would not have a second meter reading to do the calculation).

At first I thought of using a variable to control the for loop but I keep getting the following error message: "System.ListException: List index out of bounds: 15" 
I have a url field that is populated by a third party integration.  This field uses http: to populate the url link.  I would like to convert the http: portion of the url to https: maintaining the remaining url information.  Can this be done?
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?
Hi all, 

I am trying to customize Live Agent on the agent side of the chat. Specifically, we want to push a stronger notification to the agent whenever somebody initiates a chat. I know there are browser events that popup and can redirect one to the tab in question (think the notification when a calendar event is about to begin). Is there any way to replicate this in Live Agent. I've taken a look at the Live Agent developer's guide, but could not find anything there. Thanks.

-Anthony
If I upload an attachment.  Can I use trigger  flow to retrive the attachment ID and ad it to string that will create a hyperlink path to view the document istead of downloading the attachment?
Hi All

I am facing one problem when i am deploying eclipse to production.

i have one existingg project which is in my local system.

i ahs import that file in eclipse 1st .it stored in eclipse without src folder.when i am going to deply to server its showing --unable to deploy-no deployable resource found error will came


can any body share there knowledge to solve my problem
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 Eveyone,
A warm Hi to everyone.
I have one query Code completion feautures doesnot work in eclipse force.com ide.I have installed the latest plugins and java jdk7.
Still no support for code completion.
I am a java developer,for java there is so much code completion feautures avaulable,like just press space bar,and suggestion come.
Why this lack in Force.com IDE,Which is so powerful platfrom.

Correct if this exist in the force.ide and i am unable to find it.

Thanks

Question: How to bind the value selected from dynamic picklist onto controller. (I'm passing on session date 

In the below code snippet, user selects an session picklist value. Now I want to retrieve the complete session record based on selection. But when I try to assign the 'session' to an Sobject coaching__C, it is saying that its an invalid assignement of string to Sobject. How to use the selected picklist to bind/retrieve the selected session record?

Code Snippet:
public String Session {get;set;}
 
    
    public List<SelectOption> getsessionoptions() 
    {
         List<SelectOption> optionsz =  new List<SelectOption>();  
         list<coaching__C> archive = new list<coaching__c>();    
     archive = [select id,Coaching_Date__c,Coaching_Notes__c,Contact__c from Coaching__c where User__c = :UserInfo.getUserID() and Contact__c = :Subordinate]; 
                    
        for(coaching__c f:archive) {optionsz.add(new system.selectoption(f.id,string.valueof(f.Coaching_Date__c) ));}    
      
         return Optionsz; 
    }
For a demo, we needed to create a custom button on the detail page of Salesforce.com Content. The business case was to re-direct to a case page to create an issue on a document broadcasted.
How to pass the link to VF page in Description field while creating Task record?
Because "Description" field accepts only text format

Somehow I'm not getting replies in my existing post

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Ao3fIAC

I need to create a popup whenever user logs in and he has some records....i have created one VF page and kept it in home page component...and enabled...i'm not getting popup now....here is what i have done 


<apex:page wizard="true" >
 <script src="/soap/ajax/22.0/connection.js"></script>
<script src="/soap/ajax/22.0/apex.js"></script>
<script>
var queryresult = sforce.connection.query("Select Id from Position__c where Id != null");
var records = queryresult.getArray("records");
if(records != null && records.size()>0) {
window.onload= reconcile;
}
else {
window.onload = noReconcile;
}
function reconcile() {
alert('You have got POSITION RECORDS');
url='/apex/user' ;
newwindow=window.open(url,'name','height=300,width=250');
}
function noReconcile() {
alert('You have NO POSITION RECORDS');
url='/apex/user' ;
newwindow=window.open(url,'name','height=300,width=250');
}
</script>
</apex:page>

can someone tell me what is going wrong here?...do i need to call from some controller ? ...

Can someone give some idea how to approach for this quickly?....pleaseeee

Is there a way to obfuscate the username and password in the build.properties file in the Ant deployment foler? I don't like the fact that the password is sitting there in plain sight along with user name.

I am assuming there is a way to obfuscate it; could someone educate me please?

Thank you.
  • November 01, 2014
  • Like
  • 0
In the code snippet below I am able to see the Contact ID in the variable advisorIDS.  What would I add to the code to see another field on the contact record?
Thanks in Advance

public void doAutoSubscribe(Map<Id, Contact> contactMap) {
    
        Set<ID> advisorIDs = contactMap.keySet();
        system.debug(' ADVISOR ID----- >' + advisorIds);       

}
Hello everyone,

I am trying to do some data manipulation over records in a list. I was able to correctly build my list but now I am stuck with the calculations that I want to see happen.

Let's say I have record 1 and record 2 in my list. I want to grab a field called meter readings on both record and subtract the value of record 2 from the value from record 1 to get the actual energy use.

record 1 energy use = record 1 meter reading - record 2 meter reading.

And obvisouly I would like to repeat that for every records in my list except for the last one (since I would not have a second meter reading to do the calculation).

At first I thought of using a variable to control the for loop but I keep getting the following error message: "System.ListException: List index out of bounds: 15" 
I have a url field that is populated by a third party integration.  This field uses http: to populate the url link.  I would like to convert the http: portion of the url to https: maintaining the remaining url information.  Can this be done?
You can have the knowledge base on the standard portal without building a widget, is this not available in community?
I want to add standard search in my community portal . How to do if i checked it from Home page Layout but it not appearing in community page?
Hi, 

We have created VF page to show google maps on for different routes. It is working fine yesterday but now we are facing "Over query limit" and "Zero_results". 

please help me

Thanks Advance.
 
Hi all,
      I'm trying to integrate odata with salesforce. I've provided by sample request urls. I don't have endpoint url/server url. I want to see whether odata api calls from salesforce working or not. So that i can give ademo on how & wt is the functionality of Odata.


So my question is, Is it going to be possible to try odata api call in salesforce with taking some sample server and request url?
If there is anyway. Could you please post it. 
Are these accessible via APEX, Visualforce, or any of the APIs? I've been looking around and it appears the answer is no but i'm hoping someone found a way to get at them.
Okay, I am having a bit of trouble finding a solution to this predicament I am in and am hoping you guys can help me. I am trying to create a SalesForce web service that will recieve a file in the form of a byte array. The service will pass in the following paramters. Product Code, file name, and a byte array containing the contents of the file being submitted.

So, how would i go about coding this solution? I know how to do this in both C# and Java, but can't seem to find any example on how to do this with APEX code. What I think the process should be is to convert the byte array back into a FileStream, then store the doucment to SalesForce using the Document object. But I have not seen a constructor for the Document object that will take in either a byte array or a Stream object.

Any ideas?