• cropzim
  • NEWBIE
  • 35 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 25
    Replies

I am writing Apex triggers, and attempting to grab information from existing objects. The challenge is in trying to obtain the information.

 

Two questions:

1) Accounts own Opportunities. Opportunities own a custom object called Revenue__c. Revenue needs to have a lookup relationship with Account, so that the Revenue related list will appear on the Account detail page. I've written a trigger to auto-populate the Account__c lookup field on a new revenue object when the revenue object is being saved, but I'm not getting the right phrasing to grab the Acount id.
 I've tried:

 List<Revenue__c> existingRev= [SELECT ID, Opportunity__c, Account__c FROM Revenue__c];
    list<Revenue__c> listrev = new list<Revenue__c>();
            for( Revenue__c rev1 : existingRev)
            {
                rev1.Account__c = rev1.Opportunity__r.AccountId ;
                listrev.add(rev1);
            }
        update listrev;

 

But the assignment line isn't correct. Is this how you'd reference an object through another object?

 

2) In trying to grab data from a Text field and save it in the Phone field of the Contact, I'm getting Null stored there instead. Do I have to do something in order to get the text info to be accepted as a phone number?

 

Thanks.

I just reran my regression scripts on Winter 13 and oops, existing APEX code no longer works.  Anyone else seeing this?

 

Specific scenario is this code:

Set<String> aSet = new Set<String> {null, 'abc','def'};
System.debug(LoggingLevel.INFO,'aSet before remove <abc>:' + aSet);
aSet.remove('abc');
System.debug(LoggingLevel.INFO,'aSet after remove <abc>:' + aSet);
aSet.remove(null);
System.debug(LoggingLevel.INFO,'aSet  after remove <null>:' + aSet);

First debug statement displays {null,'abc','def'} as expected

Second debug statement, after removing element 'abc' displays {null,'def'} as expected

 

BUT...

We never get to the tihrd debug statement because a runtime error is thrown on aSet.remove(null) - "Argument 1 may not be null"

 

This used to work in Summer 12.  I don't see anything in the release notes indicating this functionality has been changed

  • September 12, 2012
  • Like
  • 0

OK, I'm mystified by this.

 

1. Create simple Apex class

2. Override log filters in Force.com user interface to:

LogFilterOverride

  • Database = NONE
  • Workflow = NONE
  • Validation = NONE
  • Callouts = NONE
  • Apex Code = INFO
  • Apex Profiling = NONE
  • Visualforce = NONE
  • System = NONE

 

 

3. Run Test on Class (also in Force.com UI: Setup | Develop |Apex Classes | <class> | Run Test)

 

RESULT:

  • Although APEX Profiling log filter is NONE, I still get an APEX profile
  • Although APEX Code = INFO, I still get Static variable listings - these are supposed to show only if Apex Code = FINE, FINER, FINEST
  • Furthermore, the debug log header echoed by SFDC has no bearing on the override filters I specified. Instead, it shows: 
25.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST
  • Yet, the actual Apex Code log filter is honored as only my System.debug statement at LoggingLevel.INFO is displayed whereas the line at LoggingLevel.DEBUG is not (as expected)

You might say, so what? But when you have big complex APEX classes and multiple triggers firing, and a lot of constants, the debug log fills up with all sorts of noise that gets in the way

 

By the way, here's the code:

public without sharing class MyClass { 
    public static final String MY_CONSTANT = 'My Constant';
    //    Constructor
    public MyClass() {
        

        System.debug(LoggingLevel.INFO,'should display on log filter INFO');
        System.debug(LoggingLevel.DEBUG,'should display on log filter DEBUG');
    }
    static testmethod void testMyClass () {
        MyClass myc = new MyClass();
    }
}

 

 and here's the debug log:

 

25.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST
12:46:46.443 (6443874000)|EXECUTION_STARTED
12:46:46.443 (6443924000)|CODE_UNIT_STARTED|[EXTERNAL]|01pM00000009AuA|MyClass.testMyClass
12:46:46.445 (6445382000)|USER_DEBUG|[7]|INFO|should display on log filter INFO
12:46:40.396 (6445485000)|CUMULATIVE_LIMIT_USAGE
12:46:40.396|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 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: 3 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

12:46:40.396|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
12:46:40.396|STATIC_VARIABLE_LIST|
  String:_static_MY_CONSTANT:0
  double:MIN_NORMAL:0
  double:POSITIVE_INFINITY:0
  long:serialVersionUID:0
  Boolean:TRUE:0
  double:MIN_VALUE:0
  int:SIZE:0
  int[]:sizeTable:0
  char[]:DigitOnes:0
  char[]:DigitTens:0
  String:_sfdcAdditionalCodeLocations:0
  double:NaN:0
  double:NEGATIVE_INFINITY:0
  int:MIN_VALUE:0
  int:SIZE:0
  double:MAX_VALUE:0
  String:_sfdcSuppressedCodeLocations:0
  long:serialVersionUID:0
  int:MAX_EXPONENT:0
  int:MIN_EXPONENT:0
  Boolean:FALSE:0
  String:_sfdcSuppressedCodeLocations:0
  int:MAX_VALUE:0
  char[]:digits:0
  long:serialVersionUID:0

12:46:40.396|CUMULATIVE_LIMIT_USAGE_END

12:46:46.445 (6445636000)|CODE_UNIT_FINISHED|MyClass.testMyClass
12:46:46.445 (6445647000)|EXECUTION_FINISHED
12:46:41.398|CUMULATIVE_PROFILING_BEGIN
12:46:41.398|CUMULATIVE_PROFILING|No profiling information for SOQL operations
12:46:41.398|CUMULATIVE_PROFILING|No profiling information for SOSL operations
12:46:41.398|CUMULATIVE_PROFILING|No profiling information for DML operations
12:46:41.398|CUMULATIVE_PROFILING|method invocations|
External entry point: static testMethod void testMyClass(): executed 1 time in 1 ms
Class.MyClass.<init>: line 7, column 1: global public static void debug(APEX_OBJECT, ANY): executed 1 time in 0 ms
Class.MyClass.<init>: line 8, column 1: global public static void debug(APEX_OBJECT, ANY): executed 1 time in 0 ms
Class.MyClass.testMyClass: line 11, column 1: public MyClass(): executed 1 time in 0 ms

12:46:41.398|CUMULATIVE_PROFILING_END

 Thanks

 

I'm puzzled

 

Running Eclipse Helios and Force.com IDE plug 20.0.1

 

  • On 2011-05-20, our Sandbox was on Spring 11.  If I used the IDE and did Run Tests on class Foo, I got a full debug log of the entire class execution in the Apex Test Runner view
  • On 2011-05-23, after our Sandbox was upgraded to Summer 11, running the exact same test in the IDE on class Foo yields a vastly truncated debug log in the Apex Test Runner view. The log is only about 130KB.

 

I know the code executes to completion because the same Run tests in the Force.com browser Apex Classes | Run Tests yields a debug log of 3300KB using the same log filters.

 

As far as I can tell, it is something about Summer 11 and how the Eclipse IDE version 20.0.1 obtains the debug log.

 

Any ideas greatly appreciated (I'm already filtering the log to LoggingLevel.INFO and thus avoiding the noise; but I need more than 130KB of debug log to analyze my execution).

 

 

I have a before insert and update trigger that updates the account.ownerid based on criteria that is met by matching the account.billing state to zone.state__c custom object. I created a try catch block to catch and exception and throw the error to a custom errorlog object.  But it doesn't  seem to catch it. Is this because a query exception is not considered a dml exception? alsoi have A method called getNumDMl(), does this method count all exceptions or just dml ones? I want to basically catch as many exceptions as possible and throw to error log. any advice would be great

 

catch (QueryException e)
{
Error_Log__c eLog = new Error_Log__c();
List<Error_Log__c> eLogList = new List<Error_Log__c>();
for (Integer iex = 0; iex < e.getNumDml(); iex++)
{
eLog.Description__c = e.getDmlMessage(iex);
eLogList.add(eLog);
}
insert eLogList;
}

  • September 29, 2012
  • Like
  • 0

I was wondering how can I do something like this with Apex Code:

 

IF(variable='text' && variable2='text2') variable3='value would be this', variable4='this',  variable5='this', etc, etc 

The idea is that if the value of variable and variable2 are correct this will change values on variable3, 4, 5, 6, 7, ...

 

Is this possible?

 

Thanks in advanced!

Winter 13 anomaly 

 

I have a test class Foo that among other things:

 

* inserts a ContentVersion

* inserts a ContentWorkspaceDoc

* updates the ContentVersion with custom field values and tags

 

If I login to the Winter13 sandbox using credentials for system administrator X, select class Foo and Run Tests - the tests pass fine

 

If I use Ecliipse IDE Version 24.0.0.201202291629 also logged in as user X and do Apex Test Runner on the very same class Foo, I get the error:

System.DmlException: Update failed. First exception on row 0 with id 068V00000008ILuIAM; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

where the ID is the ID of the ContentVersion record and the DML is on the Update of the ContentVersion record

 

These tests all ran fine in Eclipse prior to the sandbox being upgraded to Winter 13

 

Here's what I don't get:

Doesn't Eclipse IDE simply instruct the sandbox cloud to execute the test class Foo, all execution occurs in the sandbox cloud, and the results/log are merely passed back to Eclipse?

 

Given that the Ecliipse project uses the same credentials as those I use to UI login to the Force.com platform, the Eclipse test execution should execute the same as running the test via a Force.com Run Tests button click. True?

 

What could be different here? Does the Winter 13 sandbox code somehow execute the test class submitted by Eclipse with different context than when I execute it from the Force.com UI?  I've never seen this before and I've been running this APEX class in Eclipse successfully since V19.0

 

please suggest how can we Identify/detect Object Name from ID on visualforce page via Apex code?

 

i am trying to dynamically pick the name of standard/custom object from salesforce object id on a visualforce page.

 

please suggest if you have any ideas on that.

Thanks.

Hi

Is it possible to compress phone # is the reverse of the phone number  (example phone #  2177627123 search phone # = 3217267712) in apex?????

thanks

 

 

  • September 13, 2012
  • Like
  • 0

Hello,

 

When I create a new salesforce project and import the object from Salesforce, the following error occur.

 

An error has occurred. See error log for more details. com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor

 

Anyone have an idea about that ?

I've already try to remove eclipse, reinstall it, install it on a fresh new computer, it's the same issue.

 

 

I need to write a test class for trigger on a standard object. Account.

The plan is package the trigger and test class as a free app so users can re-use the component.

As we all know the test coverages are environment dependent.
They are dependent on factors like

(1) Custom Mandatory fields,
(2) Custom Validation rules &
(3) other custom triggers on the object

Are these best practices around creating test class for standard object which can have a good coverage irrespective of the test environment ?

I want to set start and end date of schedule job using apex code.

Cron Trigger has StartTime,EndTime fields but they are not writable.

How to set start and end date.

 

Any idea???

 

Thanks

Anil

I am writing Apex triggers, and attempting to grab information from existing objects. The challenge is in trying to obtain the information.

 

Two questions:

1) Accounts own Opportunities. Opportunities own a custom object called Revenue__c. Revenue needs to have a lookup relationship with Account, so that the Revenue related list will appear on the Account detail page. I've written a trigger to auto-populate the Account__c lookup field on a new revenue object when the revenue object is being saved, but I'm not getting the right phrasing to grab the Acount id.
 I've tried:

 List<Revenue__c> existingRev= [SELECT ID, Opportunity__c, Account__c FROM Revenue__c];
    list<Revenue__c> listrev = new list<Revenue__c>();
            for( Revenue__c rev1 : existingRev)
            {
                rev1.Account__c = rev1.Opportunity__r.AccountId ;
                listrev.add(rev1);
            }
        update listrev;

 

But the assignment line isn't correct. Is this how you'd reference an object through another object?

 

2) In trying to grab data from a Text field and save it in the Phone field of the Contact, I'm getting Null stored there instead. Do I have to do something in order to get the text info to be accepted as a phone number?

 

Thanks.

during lead convert, it can create opportunity automatically. however, during opportunity creation, it does not update opportunity product's pricebook id. from documentation, opporunity product is accessing opportunitylineitem. is there a way to set opportunitylineitem's pricebook id? i tried setting its PricebookEntryId but it does no reflect changes. anyone can give some hints? thanks.

Hi Pals,

 

Is it possible to parse/process file uploaded( for e.g. a .csv file) in apex and and fetch records? From what I know, when a file is uploaded from suppose a VF page, we will receive a Blob of that file. But there is no mechanism as such to parse that Blob and see what data is exactly is inside it. I know this I/O processing can be easily done in .Net/Java. But usually a .Net/Java solutions is not what a customer expects because of the extra hosting/costing/whatever the other reasons. So, I want to know if this possible in Apex at all ? I searched boards and also IdeaExchange but did not find any confident answer. Any help is very much appreciated.

 

Thanks

Vishnu

I have a inbound email service handling .txt attachments coming from many different users around my organisation. All emails are sent using MS outlook.

 

Sometimes the text attachment will be recognized as binary attachment, and consequently discarded. In one case I am looking at now, if i forward the troublesome email with the attachment, it will always detect the attachment as binary. However if I store the attachment on my HDD, and create a new email with this file and send it, it will work. 

 

Any thoughts are highly appreciated!

Hello.  I was wondering if anyone could give me some guidance.

 

I am having issues with the heap size of a certain VF page.  Specifically, this is being caused by an IF statement that pulls values from a large list.

 

Just as a side note...I initially was doing an aggregatedresult COUNT on the below, but due to other SOQL lists on the page, I was beginning to run into 50K limit issues.  Therefore, I thought I would just do an IF statement on whether a record met a few conditions.  If it did, I would just increase a "Count" variable by 1.

 

Well, this works...but I am getting dangerously close to the heap size limit. 

 

My page simply displays static data - so there is no need to keep any of the variables/lists in memory after the page renders.  Given that, I was thinking that I could bring the heap size down dramatically...but that is where I am having issues.

 

Thanks in advance.

 

 

// This is creating a list from a group of over 300,000 records // The "listA" that gets created below totals around 15,000 records listA = [SELECT id, Duration__c, Location__c, CustCondition__c, HappyCust__c, JoinedDate__c FROM myObject__c WHERE JoinedDate__c=TODAY OR HappyCust__c=false]; // Now I want to count the number of occurrences for records that meet a particular condition Count = 0; // resetting the counter value for (Integer a = 0; a < listA.size(); a++) {

// The below IF statement is what is causing the huge jump in heap size. I was wondering how to fix it

if(listA[a].JoinedDate__c==system.today() && listA[a].Location__c=='NE' && listA[a].Duration__c>=60) { Count = Count + 1; // increasing the counter by one } } listA = null; // I thought nulling out the big list would do the trick - but the heap is still huge

 

if I call

 

var.setPageNumber(integer.valueOf(ApexPages.CurrentPage().getParameters().get('pgNum')));

 

IT ALWAYS sets the pagenumber to 1 regardless of what the apexPages parameter

 

If I However do:

 

Public Integer tstPg = integer.valueOf(ApexPages.CurrentPage().getParameters().get('pgNum')));

var.setPageNumber(txtPg);

 

it sets the page just fine no matter what the ApexPage Parameter is. If it is 2, the page is set to 2

 

Any one have any ideas?

 

I'm puzzled

 

Running Eclipse Helios and Force.com IDE plug 20.0.1

 

  • On 2011-05-20, our Sandbox was on Spring 11.  If I used the IDE and did Run Tests on class Foo, I got a full debug log of the entire class execution in the Apex Test Runner view
  • On 2011-05-23, after our Sandbox was upgraded to Summer 11, running the exact same test in the IDE on class Foo yields a vastly truncated debug log in the Apex Test Runner view. The log is only about 130KB.

 

I know the code executes to completion because the same Run tests in the Force.com browser Apex Classes | Run Tests yields a debug log of 3300KB using the same log filters.

 

As far as I can tell, it is something about Summer 11 and how the Eclipse IDE version 20.0.1 obtains the debug log.

 

Any ideas greatly appreciated (I'm already filtering the log to LoggingLevel.INFO and thus avoiding the noise; but I need more than 130KB of debug log to analyze my execution).

 

 

Hi all.

 

We have a PHP web app talking to SF.  We have converted a Lead to an Account, and are then trying to update the account and getting the error when playing in the sandbox:

Sales Force Update object Failed: attempt to violate hierarchy constraints

 

Unfortunately, there's no documentation on this error anywhere, and it seems like we're the only ones getting it.

 

Can anyone shed some light on what this means?  The same code works fine when talking to the live SalesForce.

 

Thanks

Todd

 

  • May 01, 2009
  • Like
  • 0