• wlevy
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 11
    Replies

I am trying to run my first Apex Batch job. In this case it's a trivial update to a custom object, just a "proof of concept" as I learn the platform.

The problem is that nothing gets updated in the database. The debug log in the Anonymous Execution view even shows "Number of SOQL queries: 0 out of 100".

Following is my Apex class and the Execute Anonymous script:

 

global class Batch_UpdateTargetField implements Database.Batchable<SObject> {
    global Database.Querylocator start(Database.BatchableContext context) {
        System.debug('Start!');
        String query = 'SELECT SourceField__c, TargetField__c FROM MyCustomObject__c';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext context, List<SObject> scope) {
        for (SObject rec : scope) {
            MyCustomObject__c foo = (MyCustomObject__c)rec;
            rec.put(foo.TargetField__c, TargetFieldFromSourceField(foo.SourceField__c));
        }
        update scope;
    }
    string TargetFieldFromSourceField(string value) {
        return 'Foobar';
    }
    global void finish(Database.BatchableContext context) {
        System.debug('Finished');
    }
}

 

Script:

Batch_UpdateTargetField batch = new Batch_UpdateTargetField();
Id jobId = Database.executeBatch(batch);
System.debug('Started Batch Apex job: ' + jobId);

 

What am I missing here???

 

Thanks

  • June 27, 2012
  • Like
  • 0

I have been using the IDE plugin for Eclipse for awhile and tried today for the first time to use the Execute Anonymous view. The Active Project, Log Category, and Log Level controls are enabled, but the "Source to execute:" textbox is disabled - in fact, I don't even see a textbox, just the prompt. I have been unable to find any information on what might be causing this or how to fix it. Can anyone help?

 

Thanks

  • June 27, 2012
  • Like
  • 0

My application uses a central "launch" page in which the user drills down to reveal levels of detail and then can click detail links to navigate to various edit pages and reports. Each of these pages includes an apex:composition tag referencing a common template. The template page includes a link back to the launch page.

 

The challenge is to restore the launch page to its prior (drilled down) state when the user returns to it after navigating away. To do this we need to keep track of a handful of ID variables. Depending on how far the user drilled down, some of these ID variables may be null.

 

I'm looking for a good technique for keeping these variables in scope. I suppose they will have to be passed back and forth as querystring parameters? Is there a better way?

 

Thank you.

  • May 22, 2012
  • Like
  • 0

I discovered that someone created a custom object in our project using the wrong name. When I try to change the Object Name I get a number of validation errors because the current object name is referenced in several places (a page, a class, and a trigger). However, the system won’t let me change the referenced name in the offending apex code files – it’s a Catch 22.

 

I imagine this scenario is not uncommon. How does one go about changing an object name that’s already referenced in code? Scratching my head over this one!

  • May 11, 2012
  • Like
  • 0

I need to display a single summary value on my VF page. Given the following apex code, how do I display "Total"?

 

I'm new to apex and VF so maybe I have the wrong approach altogether.

 

private String myVar;

myVar = 'something';

 

private List<AggregateResult> summary;

public List<AggregateResult> getSummary;

 

summary = [select sum(Total__c) Total from MyTable__c where Foo__c = :myVar];

 

VF:

<td>{!Summary.Total}</td>

 

When I save my work I get this error: Unknown property 'VisualforceArrayList.Total'

 

  • May 10, 2012
  • Like
  • 0

I am trying to run my first Apex Batch job. In this case it's a trivial update to a custom object, just a "proof of concept" as I learn the platform.

The problem is that nothing gets updated in the database. The debug log in the Anonymous Execution view even shows "Number of SOQL queries: 0 out of 100".

Following is my Apex class and the Execute Anonymous script:

 

global class Batch_UpdateTargetField implements Database.Batchable<SObject> {
    global Database.Querylocator start(Database.BatchableContext context) {
        System.debug('Start!');
        String query = 'SELECT SourceField__c, TargetField__c FROM MyCustomObject__c';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext context, List<SObject> scope) {
        for (SObject rec : scope) {
            MyCustomObject__c foo = (MyCustomObject__c)rec;
            rec.put(foo.TargetField__c, TargetFieldFromSourceField(foo.SourceField__c));
        }
        update scope;
    }
    string TargetFieldFromSourceField(string value) {
        return 'Foobar';
    }
    global void finish(Database.BatchableContext context) {
        System.debug('Finished');
    }
}

 

Script:

Batch_UpdateTargetField batch = new Batch_UpdateTargetField();
Id jobId = Database.executeBatch(batch);
System.debug('Started Batch Apex job: ' + jobId);

 

What am I missing here???

 

Thanks

  • June 27, 2012
  • Like
  • 0

I have been using the IDE plugin for Eclipse for awhile and tried today for the first time to use the Execute Anonymous view. The Active Project, Log Category, and Log Level controls are enabled, but the "Source to execute:" textbox is disabled - in fact, I don't even see a textbox, just the prompt. I have been unable to find any information on what might be causing this or how to fix it. Can anyone help?

 

Thanks

  • June 27, 2012
  • Like
  • 0

My application uses a central "launch" page in which the user drills down to reveal levels of detail and then can click detail links to navigate to various edit pages and reports. Each of these pages includes an apex:composition tag referencing a common template. The template page includes a link back to the launch page.

 

The challenge is to restore the launch page to its prior (drilled down) state when the user returns to it after navigating away. To do this we need to keep track of a handful of ID variables. Depending on how far the user drilled down, some of these ID variables may be null.

 

I'm looking for a good technique for keeping these variables in scope. I suppose they will have to be passed back and forth as querystring parameters? Is there a better way?

 

Thank you.

  • May 22, 2012
  • Like
  • 0

I discovered that someone created a custom object in our project using the wrong name. When I try to change the Object Name I get a number of validation errors because the current object name is referenced in several places (a page, a class, and a trigger). However, the system won’t let me change the referenced name in the offending apex code files – it’s a Catch 22.

 

I imagine this scenario is not uncommon. How does one go about changing an object name that’s already referenced in code? Scratching my head over this one!

  • May 11, 2012
  • Like
  • 0

I need to display a single summary value on my VF page. Given the following apex code, how do I display "Total"?

 

I'm new to apex and VF so maybe I have the wrong approach altogether.

 

private String myVar;

myVar = 'something';

 

private List<AggregateResult> summary;

public List<AggregateResult> getSummary;

 

summary = [select sum(Total__c) Total from MyTable__c where Foo__c = :myVar];

 

VF:

<td>{!Summary.Total}</td>

 

When I save my work I get this error: Unknown property 'VisualforceArrayList.Total'

 

  • May 10, 2012
  • Like
  • 0