• Davy Huijgens
  • NEWBIE
  • 150 Points
  • Member since 2015


  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 27
    Replies
Do we have to run test classes for classes created in sandbox if they are for our own production org?
The code works perfectly well in our snadbox, but we have not created any test classes for it yet. 
I have a requirement of doing a callout on case creation and based on the response(JSON) received update the case record. I need to do a callout and send case Id and case subject in the request body to external system. I am facing problem in serializing the request. Below is the code for the same. Please let me know what is wrong with this code:
Trigger-
trigger caseTrigger on Case (after insert,after update) {
    
    if(trigger.isInsert){
        for(case c : trigger.new){
           
           checkCaseClass.checkCase(c.id,c.subject);
        }
    }
}    
Helper class-
public class checkCaseClass{
@future (callout=true)
 public static void checkCase(Id CaseId, string subject){
        
        for(case c:[select id,subject,description from case where id =: caseId]){
            Http http = new Http();
            HttpRequest req = new HttpRequest();
            req.setHeader('Content-Type','application/json');
            String endpoint = 'any end point';
            req.setMethod('POST');
            req.setEndpoint(endpoint);
            req.setBody('CaseId='+EncodingUtil.urlEncode(CaseId, 'UTF-8')+'subject='+EncodingUtil.urlEncode(subject, 'UTF-8');
            String s= JSON.serialize(req);
            HTTPResponse response = http.send(req);
            system.debug('response -->'+response);
    }
}
}

When above code is executed, I get error - System.JSONException: Apex Type unsupported in JSON: System.HttpRequest.

Please let me know the possible solution for this.
Hi everyone,

I am looking for some help with writing a test class for the below extension controller:
 
/*
 * Extension controller for calling Breakthrough Application Settings.
 *
 * HH, Breakthrough Collaborative, 2017
 */

public class ApplicationDisplayController {

	public Breakthrough_Application_Settings__c settings { get; set; }
	public Boolean isDisplayed { get; set; }

	public ApplicationDisplayController(MyProfileController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(AlumniSearchController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(JobBoardSearchController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(ResourceLibraryController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}
}

I am just learning Salesforce coding, so I am very shaky on writing test classes.  Thanks in advance for any help or feedback.
Hi all,I am trying to create VF email template. I have account object and inside account I have custom object "Invoices", I need help how we can get "Invoices” object fields into template.

My sample code is –
Messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Invoice__c">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
 
<messaging:htmlEmailBody >
<b> Dear  {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your Virtuagym subscription for the total amount of currency_and_total_amount. <br/>
        <table>
            <tr>
                <th>Invoice Number</th>
            </tr>
           
            <apex:repeat var="cx" value="{!relatedTo.Account_invoice__r}" >
               <tr>
                        <td>{!cx.Invoice_Number__c}</td>
               </tr>
                                   
            </apex:repeat>
        </table>                        
 
I am also getting error – “Error: Invalid field Invoice_Number__r for SObject Account”
Additional Info :-
- Invoice__c : Is API name of my Custom Object Invoices
- Account_invoice__c - Child Relationship Name of Invoices with Accounts
Hi All,

I am trying to display vf pages based on record type selected from standard salesforce page. I have two record types API Names are - RecordType1, RecordType2. Customer__c is object api name. After selecting record type and clicking on next button, i am getting below error.


Visualforce Error
Help for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!redirectToNewVFPage}' in component <apex:page> in page recordtypepage: Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1
Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1

Below is the code.

public with sharing class NewCustomerExtension {

    public String recordTypeId;

    public NewCustomerExtension (ApexPages.StandardController std) {

    }

    public Pagereference redirectToNewVFPage(){
        Pagereference pg = null;
        if(ApexPages.CurrentPage().getParameters().get('RecordType') != null){
            recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
            if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType1').getRecordTypeId()){
               // pg = new Pagereference('/apex/Page1');
               pg = Page.Page1;   
            }else if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType2').getRecordTypeId()){
               // pg = new Pagereference('/apex/Page2'); // Add Parameters to Page if Needed
               pg= Page.Page2;
            }
            pg.setRedirect(true);
            return pg;
        }
        return null;
    }
}

Page Name: RecordTypePage
<apex:page standardController="Customer__c" extensions="NewCustomerExtension" action="{!redirectToNewVFPage}">
</apex:page>

PageName: Page1:
<apex:page standardController="Customer__c" >
   Page 1
</apex:page>

PageName: page2
<apex:page standardController="Customer__c" >
  <h1>Congratulations</h1>
  This is your new Page
</apex:page>

I have overrided New button with page: RecordTypePage.

Plz let me know how to redirect to their respective pages. Thanks in advance.

 
I have implemented a QuickAction.QuickActionDefaultsHandler to prepopulate the email action in the case feed in the service console.

In the handler I want to set the subject of the email, this is done like this:
 
if(sendEmailDefaults.getInReplyToId() != null){
    emailMessage.Subject = 'Re: ';    
}else{
    if(et.Subject != null){
        emailMessage.Subject = et.Subject;
    }else{
        emailMessage.Subject = c.Subject;
    }
}

This works fine, until I also set an EmailTemplate:
 
sendEmailDefaults.setTemplateId(et.Id);
sendEmailDefaults.setIgnoreTemplateSubject(true);
sendEmailDefaults.setInsertTemplateBody(true);

Now the subject just defaults back to the orignal subject of the EmailMessage targetSObject of the QuickAction.SendEmailQuickActionDefaults.

Anybody have any idea why this is happening?
Hi 

when i am changeing the parent opportunity in opportunity record i am geting error.
can any one can help me out to debug the error or someone else faced this type of issue

Error:-"The Record couldn't be saved because it failed to trigger a flow  A flow trigger failed  to excute the flow with version ID 3011B00000taq . Flow error message :<b> An unhandled Fault has occurred in this flow </b> <br> An unhandled fault has occurred while processing the flow .please contact your system adminstrator for more information "

Thanks in Advance
​satya
 
I have a fomula field on the Lead object that calculates the number of days a lead is in a specific queue. If the Lead is converted, we want to stop the formula field from counting and preserve the last number displayed (mapped to the contact record upon conversion. Is this possible?
i want to write trigger to popolate account owner name into SalesRep__c(Text) field on the account object.
Do we have to run test classes for classes created in sandbox if they are for our own production org?
The code works perfectly well in our snadbox, but we have not created any test classes for it yet. 
hi..need a help in query...oh batch class
Error is : unexpected token: ')' 
We would like to move leads currently in the Working or Busy status that do not have completed tasks in the last 30 days to the ABC status.
  • Lead Status = Working, Busy
  • Last Activity Date < Today – 30

We want to scheduale a batch class daily basis...here is the code..
global class Leadinactiveflow implements Database.Batchable<SObject>

{

 global Database.Querylocator start (Database.BatchableContext BC)
  {
         
   String query = 'SELECT Id, Status, LastActivityDate ,(select id, createdDate,status from Tasks )From Lead WHERE Status in (\'Working\', \'Busy\')  AND  (Today() - LastActivityDate) > 30';
   System.debug(query);

      return Database.getQueryLocator(query);          

  }
  global void execute (Database.BatchableContext BC, List <Lead> scope)

  {

   List<Lead> listLead = new List<Lead>();

    for(Lead l : scope)
     {
      
         l.Status = 'ABC';     

      listLead.add(l);

      }

   
         if(!listLead.isEmpty()){
            update listLead;
        } 

  } 

global void finish (Database.BatchableContext BC)

{

}

}
Schedulable class is :
 
global with sharing class SchedulerForBatchApex implements Schedulable

{
    global void execute(SchedulableContext sc)        

  {
      Leadinactiveflow b = new Leadinactiveflow();
      ID BatchID = Database.executeBatch(new Leadinactiveflow(), 200);
  }

Public static void SchedulerMethod() 

    {
    string con_exp='0 0 1 * * ?';

    System.schedule('LeadinactiveflowTest', con_exp, new SchedulerForBatchApex());
                                     
    }   

}


 
  • September 01, 2017
  • Like
  • 0
i have some confusion working with batch apex. We use batch apex working with larger set of data. give me one example of it and why its methods and implementing class is global?
  • August 31, 2017
  • Like
  • 0
Hey guys I am completed a controller extension that sends data to a VF page and then the VF page displays it as a table.

Now, I wrote a unit test class for the controller extension. It has 100% coverage but it is failing unfortunately... 

This is my VF page:
 
<apex:page standardController="Case" extensions="FirstProjectController"> 
       
    <!-- Accounts with Open Cases -->
    <apex:pageBlock title="Table of Accounts with Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
  
    <!-- Accounts with No Cases -->
    <apex:pageBlock title="Table of Accounts with no Cases">
        <apex:pageBlockTable value="{!Accounts}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Five most Recent Cases -->
    <apex:pageBlock title="Table of the Five most Recent Cases">
        <apex:pageBlockTable value="{!cases2}" var="c">
            <apex:column value="{!c.Subject}"/>
            <apex:column value="{!c.CreatedDate}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
       
</apex:page>

This is my Apex code: 
public class FirstProjectController {
	public Case myCase {get; set;}
    
    //Lists used to transfer data into the VF page
    public List<Case> cases {get; set;} 
    public List<Account> accounts {get; set;} 
    public List<Case> cases2 {get; set;} 
    
    //Lists that initialize the querys   
    //Query Obtains the Accounts with open cases 
	public List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];   

    //Query Obtains the Accounts with no cases
    public List<Account> queryTwo = [Select Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Case) ORDER BY Name ASC];

    //Query Obtains the 5 most recent cases
    public List<Case> queryThree = [SELECT Subject, CreatedDate FROM Case ORDER BY CreatedDate DESC Limit 5];
    
    public FirstProjectController(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();   
    
        //Transfer the data into the VF page
        this.cases = queryOne;         	      
    	this.accounts = queryTwo;            
        this.cases2 = queryThree;        
    }
}

This is my actual test code:
 
@isTest 
public class FirstProjectControllerTest {

    public static testMethod void testMyController() {
        
        //Create a new Case
        Case caseOne = new Case(Subject='Testing 1');
        
        //Insert the new Case into Cases
        insert caseOne;
        
        //Check that caseOne is not null
        System.assertNotEquals(caseOne,null);
        
        //Instantiate the extension and controller
        ApexPages.StandardController ctrl = new ApexPages.StandardController(caseOne);
		FirstProjectController ext = new FirstProjectController(ctrl);
        
        //Run the first query from the FirstProject Class
        List<Case> queryOne = [SELECT AccountId, Status, Subject FROM Case WHERE Id =:caseOne.Id];
        
        //Check that caseOne has the correct subject
        System.assertEquals('Testing 1', caseOne.Subject);
        
        //Check that caseOne is a new Case
        System.assertEquals('new', caseOne.Status);
        
    }
}

Any form of help would be greatly appreciated!
 
I have a requirement of doing a callout on case creation and based on the response(JSON) received update the case record. I need to do a callout and send case Id and case subject in the request body to external system. I am facing problem in serializing the request. Below is the code for the same. Please let me know what is wrong with this code:
Trigger-
trigger caseTrigger on Case (after insert,after update) {
    
    if(trigger.isInsert){
        for(case c : trigger.new){
           
           checkCaseClass.checkCase(c.id,c.subject);
        }
    }
}    
Helper class-
public class checkCaseClass{
@future (callout=true)
 public static void checkCase(Id CaseId, string subject){
        
        for(case c:[select id,subject,description from case where id =: caseId]){
            Http http = new Http();
            HttpRequest req = new HttpRequest();
            req.setHeader('Content-Type','application/json');
            String endpoint = 'any end point';
            req.setMethod('POST');
            req.setEndpoint(endpoint);
            req.setBody('CaseId='+EncodingUtil.urlEncode(CaseId, 'UTF-8')+'subject='+EncodingUtil.urlEncode(subject, 'UTF-8');
            String s= JSON.serialize(req);
            HTTPResponse response = http.send(req);
            system.debug('response -->'+response);
    }
}
}

When above code is executed, I get error - System.JSONException: Apex Type unsupported in JSON: System.HttpRequest.

Please let me know the possible solution for this.
I am not a developer - not even close. I have a request to update fields to null when criteria is met and one of the fields is a multi-select picklist and I'm having a hard time accomplishing this request with workflow/field update or Process Builder. I believe this could be accomplished with a trigger but I know nothing about them. I have googled triggers and I've attempted to write one and I know it won't work as-is but maybe it will shed some light on what I'm trying to do. The request is: if the record type = 'x' and the record owner is changed to 'x', then set the status to Active and set the other 3 fields to null. 

for (Lead l : Trigger.new) {
 if (l.RecordTypeId = '012V00000008yPS' &&
     l.OwnerId = '00500000006xlI8')
    l.LeadStatus = 'Active';
    l.Blitz_Yield_Disposition__c = null;
    l.Blitz_Yield_Disposition_Reason__c = null;
    l.Blitz_Yield_Month__c = null;
     update l;
}
 
Hi everyone,

I am looking for some help with writing a test class for the below extension controller:
 
/*
 * Extension controller for calling Breakthrough Application Settings.
 *
 * HH, Breakthrough Collaborative, 2017
 */

public class ApplicationDisplayController {

	public Breakthrough_Application_Settings__c settings { get; set; }
	public Boolean isDisplayed { get; set; }

	public ApplicationDisplayController(MyProfileController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(AlumniSearchController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(JobBoardSearchController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}

	public ApplicationDisplayController(ResourceLibraryController ctrlParam) {
	    this.settings = [select Display__c,
	                Name 
	              from Breakthrough_Application_Settings__c 
	              where Active__c = true LIMIT 1];
	    this.isDisplayed = settings.Display__c;
	}
}

I am just learning Salesforce coding, so I am very shaky on writing test classes.  Thanks in advance for any help or feedback.
Hi all,I am trying to create VF email template. I have account object and inside account I have custom object "Invoices", I need help how we can get "Invoices” object fields into template.

My sample code is –
Messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Invoice__c">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
 
<messaging:htmlEmailBody >
<b> Dear  {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your Virtuagym subscription for the total amount of currency_and_total_amount. <br/>
        <table>
            <tr>
                <th>Invoice Number</th>
            </tr>
           
            <apex:repeat var="cx" value="{!relatedTo.Account_invoice__r}" >
               <tr>
                        <td>{!cx.Invoice_Number__c}</td>
               </tr>
                                   
            </apex:repeat>
        </table>                        
 
I am also getting error – “Error: Invalid field Invoice_Number__r for SObject Account”
Additional Info :-
- Invoice__c : Is API name of my Custom Object Invoices
- Account_invoice__c - Child Relationship Name of Invoices with Accounts
I do not need a trigger for it to work in the Sandbox...all I am doing is using SQL to pull the Child Line itmes into an Email Template driven by the Parent RMA Object.

Below is my Apex Class and below that is my VF email template.  It works fine in my sandbox, but the Apex class has 0%code coverage so I cannot movie into Production....I will really appreciate any help

Apex Class (Parts Orders (po) is the master/parent record and PROL are the Detail/Child records (line items) that need to show up in the Parts Order driven email template):

public  class poTemplt
{
    public Id poId {get;set;}
    public List<Parts_Reqs_Orders_Line__c> getpols()
    {
        List<Parts_Reqs_Orders_Line__c> pol;
        pol = [SELECT Id,Name,PROL_Expected_Quantity__c,PROL_Date_Required_By__c,
PROL_Line_Status__c,PROL_Parts_Reqs_Orders__c,PROL_Product_Model__c,PROL_Product_Model__r.name,PROL_Model_Description__c,PROL_Serial_Number__r.SVMXC__Serial_Lot_Number__c,PROL_Serial_Number__c,
PROL_Tracking_Number__c,Related_Case__c,Related_Case__r.CaseNumber 
FROM Parts_Reqs_Orders_Line__c WHERE PROL_Parts_Reqs_Orders__c =: poId];
        return pol;
    }
}

Visualforce Component (VF Component is a list on the Email template with all the line items associated with the RMA's ID:
<apex:component controller="poTemplt" access="global"> <apex:attribute name="PartOdersId" type="Id" description="Id of the Part Order" assignTo="{!poId}"/> <table border = "2" cellspacing = "2"> <tr> <td>RMA Line Number</td> <td>Line Status</td> <td>Related Case</td> <td>Model</td> <td>Model Description</td> <td>Quantity</td> <td>Serial Number</td> <td>Date Required By</td> <td>Tracking Number</td> </tr> <apex:repeat value="{!pols}" var="p"> <tr> <td>{!p.Name}</td> <td>{!p.PROL_Line_Status__c}</td> <td>{!p.Related_Case__r.CaseNumber}</td> <td>{!p.PROL_Product_Model__r.name}</td> <td>{!p.PROL_Model_Description__c}</td> <td>{!p.PROL_Expected_Quantity__c}</td> <td>{!p.PROL_Serial_Number__r.SVMXC__Serial_Lot_Number__c}</td> <td>{!p.PROL_Date_Required_By__c}</td> <td>{!p.PROL_Tracking_Number__c}</td> </tr> </apex:repeat> </table> </apex:component>

I have read through the documentation on Apex testing and most is based on the trigger, but I haven't need a trigger for this fundtionality and I cannot set the Apex Class test up based on the little I have learned from the docuementation.  Please help my users really need this functionality.

Thanks
Kate
 
I have implemented a QuickAction.QuickActionDefaultsHandler to prepopulate the email action in the case feed in the service console.

In the handler I want to set the subject of the email, this is done like this:
 
if(sendEmailDefaults.getInReplyToId() != null){
    emailMessage.Subject = 'Re: ';    
}else{
    if(et.Subject != null){
        emailMessage.Subject = et.Subject;
    }else{
        emailMessage.Subject = c.Subject;
    }
}

This works fine, until I also set an EmailTemplate:
 
sendEmailDefaults.setTemplateId(et.Id);
sendEmailDefaults.setIgnoreTemplateSubject(true);
sendEmailDefaults.setInsertTemplateBody(true);

Now the subject just defaults back to the orignal subject of the EmailMessage targetSObject of the QuickAction.SendEmailQuickActionDefaults.

Anybody have any idea why this is happening?