• thedabbler
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 12
    Replies

 

I am wrting a trigger that changes the owner of the case to different Queue based on certain criteria.

But as I changed the Case owner the notification email is being sent. How do I prevent that?

 

I did some searching but couldn't find a setting to disable this. In the Case Support Setting I have this unchecked.So, I think I am good on that.

 

Notify Case Owners when Case Ownership ChangesNot Checked

 

I did try this :

 

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.emailHeader.triggerAutoResponseEmail = false;
theCase.setOptions(dlo);

 

But this is also not working. Is there a solution for this?

 

Appreciate the help.

 

Thanks

 

In the dubug log I don't see heap size any more.Why is that? I thought I used to see it before.But when I do Limits.getHeapSize() I am getting some value. And I understand that call is costly so I wouldn't want to do that. I want to monitor this as I am dealing with large sets of data and don't wanna hit that up.

 

Here is some Limit usage statistics :

 Number of SOQL queries: 3 out of 100
  Number of query rows: 5 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 499 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10

I have a custom object call 'Complaints' which has a status picklist field.  I created a trigger to write a record (another custom object called Complaint Status Record, I'll call it CSR for short) when the Status is changed.  The trigger does not work when the the status is 'New' when the complaint record is first created.

Senario 1

- Create a Complaint, default status 'New'

- Edit Complaint, Change status 'New' to 'Step 1' - No  CSR **BAD**

- Edit Complaint, Change status 'Step 1' to 'Step 2' - CSR Created *Good*

From here I can change it to anything. New, Step 3, Step 15, Closed, etc., it will create a CSR record.

 

Senario 2 - Edit Status Field.  Change default status to 'Step 1'

CSR writes on 1st update and all updates after. (It works correctly)

 

Senario 3 - Edit Status Field.  Change back to 'New' but rename to 'New Complaint'

CSR writes 1st update and all updates after. (It works correctly)

 

Senario 4 - change Status back to 'New' uncheck default box.

Same symptoms as Senario 1.

 

I checked all Workflow Rules, deactivated all the rules on complaints at one point.  No change.  I checked triggers, no triggers that should affect complaints at all (at least to my knowledge).

 

Is 'New' in a status field a reserved word?

Hello,

     I have this class in my org and we are in process of cleaning up some stuff but i have no idea what exactly this code does, it's not related to any object, do any one have any idea on this? if i delete this does it cause any problem to my org? couldn't post the whole code bcz it's not letting me to exceed more than 20000 chrs

 


/*
* A JSONObject is an unordered collection of name/value pairs. Its
* external form is a string wrapped in curly braces with colons between the
* names and values, and commas between the values and names. The internal form
* is an object having <code>get</code> and <code>opt</code> methods for
* accessing the values by name, and <code>put</code> methods for adding or
* replacing values by name. The values can be any of these types:
* <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,
* <code>Number</code>, <code>String</code>, or the <code>JSONObject.NULL</code>
* object. A JSONObject constructor can be used to convert an external form
* JSON text into an internal form whose values can be retrieved with the
* <code>get</code> and <code>opt</code> methods, or to convert values into a
* JSON text using the <code>put</code> and <code>toString</code> methods.
* A <code>get</code> method returns a value if one can be found, and throws an
* exception if one cannot be found. An <code>opt</code> method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
* <p>
* The generic <code>get()</code> and <code>opt()</code> methods return an
* object, which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and type
* coersion for you.
* <p>
* The <code>put</code> methods adds values to an object. For example, <pre>
* myString = new JSONObject().put('JSON', "Hello, World!").toString();</pre>
* produces the string <code>{"JSON": "Hello, World"}</code>.
* <p>
* The texts produced by the <code>toString</code> methods strictly conform to
* the JSON sysntax rules.
* The constructors are more forgiving in the texts they will accept:
* <ul>
* <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear just
* before the closing brace.</li>
* <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single
* quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces,
* and if they do not contain any of these characters:
* <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
* and if they are not the reserved words <code>true</code>,
* <code>false</code>, or <code>null</code>.</li>
* <li>Keys can be followed by <code>=</code> or <code>=></code> as well as
* by <code>:</code>.</li>
* <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as
* well as by <code>,</code> <small>(comma)</small>.</li>
* <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
* <code>0x-</code> <small>(hex)</small> prefix.</li>
* <li>Comments written in the slashshlash, slashstar, and hash conventions
* will be ignored.</li>
* </ul>
* @author JSON.org
* @version 3
*/

/*
* Sept 2008, rhess
* begin simple port of this code to Force.com Apex Code
* currently this code is only building Apex objects from JSON,
* not outputing JSON from Apex
* Oct add valueToString
*/
public class value {
/* apex object to store one of several different data types
* see : http://www.json.org/
*/
public value() { }
public value(boolean bb) { bool = bb;}
public value(integer ii) {num=ii;}
public value(Decimal ii) {dnum= ii;}
public value(string st) {str=st;}
public value( jsonobject oo) { obj = oo; }
public value( list<value> vary ) { values = vary; }

public string str {get;set;}
public integer num {get;set;}
public double dnum {get;set;}
public JSONObject obj {get;set;}
public list<value> values {get;set;} // array
public boolean bool {get;set;}
// if all members are null, value == null
// isNull()
/*
* value to string is used to output JSON for Google Visualization API
*/
public string valueToString() {
if ( this.bool != null ) return (this.bool?'true':'false');
if ( this.str != null ) return '"'+this.str +'"';
if ( this.num != null ) return String.valueof(this.num);
if ( this.dnum != null ) return String.valueof(this.dnum);
if ( this.values != null ) {
string ret = '[';
for ( value v:this.values) {
//system.debug( v );
ret += v.valueToString() + ',';
}
if ( this.values.size() > 0 ) {
// remove last comma
ret = ret.substring(0,ret.length()-1);
}
return ret + ']';
}
if ( this.obj != null ) {
return this.obj.valueToString();
}
return 'null';
}

} // end of class value

/* **
* The map where the JSONObject's properties are kept.
*/
private map<string,value> data = new map<string,value>();

public value getValue(string key) { return data.get(key); }

/* **
* Construct an empty JSONObject.
*/
public JSONObject() { }

/*
* Construct a JSONObject from a JSONTokener.
* @param x A JSONTokener object containing the source string.
* @ If there is a syntax error in the source string.
*/
public JSONObject(JSONTokener x) {
this();
string c;
String key;

if (x.nextClean() != '{') {
throw new jsonexception('A JSONObject text must begin with {');
}
for (;;) {
c = x.nextClean();
if ( c == null) {
throw new jsonexception('A JSONObject text must end with }');
} else if ( c== '}' ) {
return;
} else {
x.back();

key = (string)x.nextValue().str;
// system.debug( 'key is :'+key); }
}

/*
* The key is followed by ':'. We will also tolerate '=' or '=>'.
*/

c = x.nextClean();
if (c == '=') {
if (x.next() != '>') {
x.back();
}
} else if (c != ':') {
throw new jsonexception('Expected a : after a key');
}

putOpt(key, x.nextValue()); // load next value into data map

/*
* Pairs are separated by ','. We will also tolerate ';'.
*/

string nc = x.nextClean();
if ( nc == ';' || nc == ',' ) {
if (x.nextClean() == '}') {
return;
}
x.back();
} else if ( nc == '}' ) {
return;
} else {
throw new jsonexception('Expected a , or }');
}
}
}



/* **
* Construct a JSONObject from a source JSON text string.
* This is the most commonly used JSONObject constructor.
* @param source A string beginning
* with <code>{</code>&nbsp;<small>(left brace)</small> and ending
* with <code>}</code>&nbsp;<small>(right brace)</small>.
* @exception JSONException If there is a syntax error in the source string.
*/
public static JSONObject instance(String source) {
return new JSONObject( new JSONTokener(source) );
}
public JSONObject (String source) {
this( new JSONTokener(source) );
}


/* **
* Produce a string from a double. The string 'null' will be returned if
* the number is not finite.
* @param d A double.
* @return A String.

public static String doubleToString(double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return 'null';
}
// Shave off trailing zeros and decimal point, if possible.
String s = Double.toString(d);
if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) {
while (s.endsWith('0')) {
s = s.substring(0, s.length() - 1);
}
if (s.endsWith('.')) {
s = s.substring(0, s.length() - 1);
}
}
return s;
}
*/

/* **
* Get the value object associated with a key.
*
* @param key A key string.
* @return The object associated with the key.
* @throws JSONException if the key is not found.
*/
public object get(string key) {
value ret = this.data.get(key);
if (ret == null) {
throw new JSONException('JSONObject[' + key + '] not found.');
}
if ( ret.str != null ) return ret.str;
if ( ret.num != null ) return ret.num;
if ( ret.bool != null ) return ret.bool;
system.assert( ret.obj == null , 'get cannot return nested json ojects');
// array?
return null;
}


/* **
* Get the boolean value associated with a key.
*
* @param key A key string.
* @return The truth.
* @throws JSONException
* if the value is not a Boolean or the String 'true' or 'false'.
*/
public boolean getBoolean(String key) {
Object o = this.get(key);
if ( o!=null) return (boolean) o;
throw new JSONException('JSONObject[' + key + '] is not a Boolean.');
}


/* **
* Get the double value associated with a key.
* @param key A key string.
* @return The numeric value.
* @ if the key is not found or
* if the value is not a Number object and cannot be converted to a number.

public double getDouble(String key) {
Object o = get(key);
try {
return o instanceof Number ?
((Number)o).doubleValue() :
Double.valueOf((String)o).doubleValue();
} catch (Exception e) {
throw new JSONException('JSONObject[' + quote(key) +
'] is not a number.');
}
}*/


/* **
* Get the int value associated with a key. If the number value is too
* large for an int, it will be clipped.
*
* @param key A key string.
* @return The integer value.
* @throws JSONException if the key is not found or if the value cannot
* be converted to an integer.

public int getInt(String key) {
Object o = get(key);
return o instanceof Number ?
((Number)o).intValue() : (int)getDouble(key);
} */


/*
* Get the JSONArray value associated with a key.
*
* @param key A key string.
* @return A JSONArray which is the value.
* @throws JSONException if the key is not found or
* if the value is not a JSONArray.

public JSONArray getJSONArray(String key) {
Object o = get(key);
if (o instanceof JSONArray) {
return (JSONArray)o;
}
throw new JSONException('JSONObject[' + quote(key) +
'] is not a JSONArray.');
}*/


/* **
* Get the JSONObject value associated with a key.
*
* @param key A key string.
* @return A JSONObject which is the value.
* @throws JSONException if the key is not found or
* if the value is not a JSONObject.

public JSONObject getJSONObject(String key) {
Object o = get(key);
if (o instanceof JSONObject) {
return (JSONObject)o;
}
throw new JSONException('JSONObject[' + quote(key) +
'] is not a JSONObject.');
}
*/

/* **
* Get the long value associated with a key. If the number value is too
* long for a long, it will be clipped.
*
* @param key A key string.
* @return The long value.
* @throws JSONException if the key is not found or if the value cannot
* be converted to a long.

public long getLong(String key) {
Object o = get(key);
return o instanceof Number ?
((Number)o).longValue() : (long)getDouble(key);
}
*/

/* **
* Get an array of field names from a JSONObject.
*
* @return An array of field names, or null if there are no names.

public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
return null;
}
Iterator i = jo.keys();
String[] names = new String[length];
int j = 0;
while (i.hasNext()) {
names[j] = (String)i.next();
j += 1;
}
return names;
}
*/

/* **
* Get an array of field names from an Object.
*
* @return An array of field names, or null if there are no names.

public static String[] getNames(Object object) {
if (object == null) {
return null;
}
Class klass = object.getClass();
Field[] fields = klass.getFields();
int length = fields.length;
if (length == 0) {
return null;
}
String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
} */



/* **
* Get the string associated with a key.
*
* @param key A key string.
* @return A string which is the value.
* @throws JSONException if the key is not found.
*/
public String getString(String key) {
return this.data.get(key).str;
}


/* **
* Determine if the JSONObject contains a specific key.
* @param key A key string.
* @return true if the key exists in the JSONObject.
*/
public boolean has(String key) {
return this.data.containsKey(key);
}


/* **
* Determine if the value associated with the key is null or if there is
* no value.
* @param key A key string.
* @return true if there is no value associated with the key or if
* the value is the JSONObject.NULL object.

public boolean isNull(String key) {
return JSONObject.NULL.equals(opt(key));
}
*/

/* **
* Get an enumeration of the keys of the JSONObject.
*
* @return A set of the keys.
*/
public set<string> keys() {
return this.data.keySet();
}


/* **
* Get the number of keys stored in the JSONObject.
*
* @return The number of keys in the JSONObject.
*/
public integer length() {
return this.data.keySet().size();
}


/* **
* Produce a JSONArray containing the names of the elements of this
* JSONObject.
* @return A JSONArray containing the key strings, or null if the JSONObject
* is empty.

public JSONArray names() {
JSONArray ja = new JSONArray();
Iterator keys = keys();
while (keys.hasNext()) {
ja.put(keys.next());
}
return ja.length() == 0 ? null : ja;
}

/* **
* Produce a string from a Number.
* @param n A Number
* @return A String.
* @ If n is a non-finite number.

public static String numberToString(Number n)
{
if (n == null) {
throw new JSONException('Null pointer');
}
testValidity(n);

// Shave off trailing zeros and decimal point, if possible.

String s = n.toString();
if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) {
while (s.endsWith('0')) {
s = s.substring(0, s.length() - 1);
}
if (s.endsWith('.')) {
s = s.substring(0, s.length() - 1);
}
}
return s;
} */


/* **
* Get an optional value associated with a key.
* @param key A key string.
* @return An object which is the value, or null if there is no value.
*/
public Object opt(String key) {
return key == null ? null : this.get(key);
}


/* **
* Get an optional boolean associated with a key.
* It returns false if there is no such key, or if the value is not
* true or the String 'true'.
*
* @param key A key string.
* @return The truth.
*/
public boolean optBoolean(String key) {
return optBoolean(key, false);
}


/* **
* Get an optional boolean associated with a key.
* It returns the defaultValue if there is no such key, or if it is not
* a Boolean or the String 'true' or 'false' (case insensitive).
*
* @param key A key string.
* @param defaultValue The default.
* @return The truth.
*/
public boolean optBoolean(String key, boolean defaultValue) {
try {
return getBoolean(key);
} catch (Exception e) {
return defaultValue;
}
}


/* **
* Put a key/value pair in the JSONObject, where the value will be a
* JSONArray which is produced from a Collection.
* @param key A key string.
* @param value A Collection value.
* @return this.
* @

public JSONObject put(String key, Collection value) {
put(key, new JSONArray(value));
return this;
}*/


/* **
* Get an optional double associated with a key,
* or NaN if there is no such key or if its value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A string which is the key.
* @return An object which is the value.

public double optDouble(String key) {
return optDouble(key, Double.NaN);
} */


/* **
* Get an optional double associated with a key, or the
* defaultValue if there is no such key or if its value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.

public double optDouble(String key, double defaultValue) {
try {
Object o = opt(key);
return o instanceof Number ? ((Number)o).doubleValue() :
new Double((String)o).doubleValue();
} catch (Exception e) {
return defaultValue;
}
} */


/* **
* Get an optional int value associated with a key,
* or zero if there is no such key or if the value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @return An object which is the value.


Hi,

 

Under "Static" I have created a user and tried to use that user in the static test method. When I am  debugging I dont see an values of the user record which I have created in the static declaration.

 

1  @isTest(seeAllData=true)
2  public class TestBiggerRevAccounts{
3
4  private static List<Account> testAccountsList;
5  static User sysAdminUser;
6  private static User userdata;
7  private static final Integer acct_cnt = 10;
8
9   static {
10      sysAdminUser = [select Id from User
11          where Profile.Name='System Administrator' and IsActive = true
12           limit 1];
13                   
14   System.runAs(sysAdminUser) {
15    userRole userroledata = new UserRole(Name = 'Test Executive');
16     insert userroledata;
17
18     Profile profiledata = [select Id FROM profile where name='System Administrator'];
19
20     userdata = new User(alias = 'user1', userroleid = userroledata.Id, email='testroleuser@test.com',                            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
21                              localesidkey='en_US', profileid = profiledata.Id, country='United States',
22                              timezonesidkey='America/Las_Angeles', username='testroleuser@test.com');
23                              
24     insert userdata;  
25     system.debug('*** user data' +userdata);
26    }
27   }
28   
29  public static testMethod void BiggerRevAccountsUnitTest()
30    {        
31     System.runAs(sysAdminUser) {
32     
33    testAccountsList = datacreatormethod.createAccounts(acct_cnt);                                                    
34   
35     Test.StartTest();       
36      system.debug('*** user details' +userdata);
37     User user = [select  Id, Mybigger1__c from User  where   Id = :userdata.Id];   
38       
39     user.Mybigger1__c = 'testlist1';
40     update user;   
41      
42       Test.StopTest();    
43        
44        PageReference BiggerRevAccountsPage = Page.BiggerRevAccounts;
45        Test.setCurrentPage(BiggerRevAccountsPage);
46        ApexPages.Standardcontroller accountController = new ApexPages.Standardcontroller(new Account());   
47    
48    BiggerAccountExt extension = new BiggerAccountExt(accountController);   
49        extension.save();   
50        
51       }
52     }  
53
54  }

 

I am not able to see any debug statement mentioned in line 25 output in the log. I am not sure why this record is not getting inserted.

Because of that debug log of line 36 is displaying output as "null" .

This is causing an issue in line 37 : "Attempt to de-reference a null object".

 

Please let me know what is the issue.

 

Thanks,

JBabu.

 

 

 

 

  • June 21, 2012
  • Like
  • 0

I am creating a MassEmailMessage and attempting to send a message to a list of contactIds. This code sends the emails as long as I don't set a whatId but the template isn't filled with data from my deviceID. When I set the whatIDs I get the "Attempt to de-reference a null object". I do call this after I have done the DML insert(devicerequest) and in debugging I can see a deviceRequest.Id is there when I call mail.WhatIds.add(deviceRequestId). Here is the code any help is greatly appreciated:

 

insert(deviceRequest);
EmailTemplate emailTemplate = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'Device_Request'];
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
mail.setSenderDisplayName(senderName); 
mail.setReplyTo(senderEmail);	
						
mail.setTargetObjectIds(contactIds); 
mail.WhatIds.add(deviceRequest.Id);
		
mail.setTemplateId(emailTemplate.id); 
			
mail.saveAsActivity = false;
Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

 

With in a trigger, I would like to flag a warning that does not prevent the DML operation but still notifies the user.  Is this possible at all?  Pretty much exactly like the addError method but still allowing the DML operation. 

Hai ,

 

How  can I add a checkbox for expanding and collapsing  a treeview ?

 

shine

 

I am wrting a trigger that changes the owner of the case to different Queue based on certain criteria.

But as I changed the Case owner the notification email is being sent. How do I prevent that?

 

I did some searching but couldn't find a setting to disable this. In the Case Support Setting I have this unchecked.So, I think I am good on that.

 

Notify Case Owners when Case Ownership ChangesNot Checked

 

I did try this :

 

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.emailHeader.triggerAutoResponseEmail = false;
theCase.setOptions(dlo);

 

But this is also not working. Is there a solution for this?

 

Appreciate the help.

 

Thanks

 

All,

 

I created a an object to hold history of a status change indefinitely (SDFC states it only holds history for 18 months). 

There there is a complaint__c object that was created before previously.  I created a new object call Complaint_Status_Record__c to record status changes.  I also created a trigger a trigger to create a new record when the Complaint's Status is changed.   But the 1st status update does not record.....all time.

 

Scenario 1.

1.) Create a Complaint Record.  NO CSR (Complaint Status Record) is created.  OK created not updated....Status is 'New' by default

2.) Edit Complaint Record, change status 'CS Investigated'. No CSR is created.  BAD. It should create a record.

3.) Edit again, change status to anything else. A CSR is created.  Good

 

*At this point I can change a status to new, are record is created, and then change it from new to anything else and it still works.  its only the first update.

 

Senario 2.

1.) Create a Complaint Record BUT I don't take the default I choose 'CS Investigated'. No CSR Record OK.

2.) Edit Compalaint Record, change status to anything else.  Good...It works.

 

Senario 3.

One time in Production, and Existing New Complaint Record was changed and it created a CSR record. I'm not sure why this worked and if it was existing before I deployed the CSR changes.

 

OK I tried to paste the trigger, but the formating off.  Does anyone have an idea before paste and format the trigger?

 

Geoff

In the dubug log I don't see heap size any more.Why is that? I thought I used to see it before.But when I do Limits.getHeapSize() I am getting some value. And I understand that call is costly so I wouldn't want to do that. I want to monitor this as I am dealing with large sets of data and don't wanna hit that up.

 

Here is some Limit usage statistics :

 Number of SOQL queries: 3 out of 100
  Number of query rows: 5 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 499 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10