• phyerlight
  • NEWBIE
  • 0 Points
  • Member since 2008

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

Hi All,

 

Hopefully someone can help me out with this one. I'm trying to create a new opportunity, in apex with some fields set in code and then pass that object to the default salesforce opportunity new/edit page.

 

A bit more information: I'm trying to create a set of specialized (certain subset of fields) cloning processes. I have a custom button on the opp view page that links to a custom VF page that allows the user to select the type of clone they want and then carry out the cloning. After cloning, the customer would like to be directed to the edit page. If I insert the clone into the database, and create a standardcontroller and use the edit method:

insert newOpp;
return (new ApexPages.StandardController(newOpp)).edit();

This works.

 

This is where I kind of start to run into trouble. There are a number of validation rules that exist on the opportunity object and so sometimes validation fails. This means that in order to be able to clone that opportunity, the user either needs to change the original opp (highly undesirable) or I some how edit the opportunity that was cloned before inserting it into the database. When I try to get an edit page for the new opp like I did above, all I get is the edit page for the original opportunity, not the cloned one. I'm assuming this is because the edit page requires an ID to function properly. So does anyone know how to use the new opportunity page for editing an opportunity in this kind of situation?

 

Thank you all for your help,

 

Kevin

Hi All,

I was wondering if there's any way to set the value of a read only field for the purposes of unit testing? In my case, I need to use check the Task.LastModifiedDate in a query and in order to test the query properly, I need to be able to set the last modified date to different values.

The only thing I can think of at the moment is to add a custom field that is assigned the value of the lastmodifieddate any time it is updated in a trigger. This of course isn't ideal.

If it can't be set, does anyone have any ideas or development patterns that got themselves around needing to do this?

Thanks.
Hi, I have a bit of a problem with a report I'm trying to generate. Perhaps my implementation is to blame.

I need to collect a list of the opportunities that don't have any open tasks on them or events that are still in the future.

My current implementation works by collecting all opportunities, then collecting all open tasks that are attached to opportunities and collecting all events that are attached to opportunities and their end date is after the current date. Then removing each of the associated opportunities from the first list of opportunities leaving the set of opportunities that don't have any open tasks or up-coming events.

The problem I'm running into is that A) lists can only hold 1000 objects and B) queries can only return 10,000 records. The first thing that comes to mind to fix this is to use the LIMIT statement in the queries and then get multiple sets of records using an offset like would normally be available in SQL. But it doesn't seem that that feature is available in SOQL.

So, how would I be able to make multiple queries starting off one where another left off? There doesn't seem to be a queryMore function in apex like there is in the API.

Any help would be appreciated. Of if I'm taking the completely wrong approach to do this, let me know and I'll try to come up with something else.

Thanks, phyerlight

Hi All,

 

Hopefully someone can help me out with this one. I'm trying to create a new opportunity, in apex with some fields set in code and then pass that object to the default salesforce opportunity new/edit page.

 

A bit more information: I'm trying to create a set of specialized (certain subset of fields) cloning processes. I have a custom button on the opp view page that links to a custom VF page that allows the user to select the type of clone they want and then carry out the cloning. After cloning, the customer would like to be directed to the edit page. If I insert the clone into the database, and create a standardcontroller and use the edit method:

insert newOpp;
return (new ApexPages.StandardController(newOpp)).edit();

This works.

 

This is where I kind of start to run into trouble. There are a number of validation rules that exist on the opportunity object and so sometimes validation fails. This means that in order to be able to clone that opportunity, the user either needs to change the original opp (highly undesirable) or I some how edit the opportunity that was cloned before inserting it into the database. When I try to get an edit page for the new opp like I did above, all I get is the edit page for the original opportunity, not the cloned one. I'm assuming this is because the edit page requires an ID to function properly. So does anyone know how to use the new opportunity page for editing an opportunity in this kind of situation?

 

Thank you all for your help,

 

Kevin

Hi All,

I was wondering if there's any way to set the value of a read only field for the purposes of unit testing? In my case, I need to use check the Task.LastModifiedDate in a query and in order to test the query properly, I need to be able to set the last modified date to different values.

The only thing I can think of at the moment is to add a custom field that is assigned the value of the lastmodifieddate any time it is updated in a trigger. This of course isn't ideal.

If it can't be set, does anyone have any ideas or development patterns that got themselves around needing to do this?

Thanks.
Hello All,

Is anyone familiar with this program. The Set Up Guide provided an apex trigger code as an example however I continue to receive a warning message everytime I save this trigger.  Is there something wrong with the code?
ErrorError: Compile Error: unexpected token: at line 1 column 9

trigger batchRun on cron__Batch_Run__c (before insert, before update) {

// This Apex trigger is designed to fire when the batch workflow scheduler
// checks the Trigger Batch Run checkbox or when changes are made to the Batch Run
// record manually.


Boolean error = false; // Var used by each batch job to flag and return an error to the Batch Run object.
String results = ''; // Batch job results, also returned to the Batch Run object.

for (cron__Batch_Run__c batchRun : Trigger.new) {
System.debug(batchRun);

if ( batchRun.cron__Completed__c != null) {
System.debug('Job is already completed');
continue; // Job has alread run, skip all this

}


if ( batchRun.cron__Trigger_Batch_Run__c == true ) {

System.debug('Trigger Batch Run set. Running batch job.');

// --------------- Batch Job Housekeeping --------------------
Datetime lastrun = Datetime.now();
Datetime nextrun;
if(batchRun.cron__Run_Every_Units__c == 'Days') {
nextrun = lastrun.addDays(batchRun.cron__Run_Every__c.intValue());
} else {
nextrun = lastrun.addHours(batchRun.cron__Run_Every__c.intValue());
}
if (nextrun < Datetime.now()) {
nextrun = Datetime.now();
}

// Create the next Batch Run and configure it so that the scheduler workflow
// adds a Trigger_Batch_Run field update in the time-based workflow queue.
cron__Batch_Run__c newJob = new cron__Batch_Run__c(
cron__Scheduled_To_Run__c = nextrun,
cron__Trigger_Batch_Run__c = false,
cron__Batch_Job_Name__c = batchRun.cron__Batch_Job_Name__c,
cron__Batch_Job__c = batchRun.cron__Batch_Job__c,
cron__Run_Every__c = batchRun.cron__Run_Every__c,
cron__Run_Every_Units__c = batchRun.cron__Run_Every_Units__c,
cron__Trigger_Scheduler_1__c = true);
insert newJob;

// Update the current Batch Run dates and uncheck batch job trigger
batchRun.cron__Completed__c = lastrun;
if (batchRun.cron__Scheduled_To_Run__c == null) {
batchRun.cron__Scheduled_To_Run__c = lastrun;
}
batchRun.cron__Trigger_Batch_Run__c = false;

// ------------ End Batch Job Housekeeping -------------------


// ----------- Begin batch jobs -----------------
if (batchRun.cron__Batch_Job_Name__c == 'Sample Batch Job') {
error = false;
results = '';

// Insert your Apex code here... be sure to set vars 'error' and 'results' to
// pass batch results back to the Batch Run object.

}

// ----------- End batch jobs -----------------

// Report Governor Limit Stats and set return values
String limitText = 'Aggregate Queries: '+
Limits.getAggregateQueries() +'/' +
Limits.getLimitAggregateQueries();
limitText += '\nSOQL Queries: '+
Limits.getQueries() +'/' +
Limits.getLimitQueries();
limitText += '\nQuery Rows: '+
Limits.getQueryRows() +'/' +
Limits.getLimitQueryRows();
limitText += '\nDML Statements: '+
Limits.getDMLStatements() +'/' +
Limits.getLimitDMLStatements();
System.debug(limitText);

batchRun.cron__Results__c = results;
batchRun.cron__Results__c += '\n\n'+limitText;
if (error) {
// write error to batch run notes field and set error flag
batchRun.cron__Result__c = 'Error';
} else {
batchRun.cron__Result__c = 'Success';
}

} else { // end if trigger batch job flag set
System.debug('Refreshing time-based workflow queue');
// Alternate Trigger Scheduler flags to keep workflow queued and current
if (batchRun.cron__Trigger_Scheduler_1__c == false) {
batchRun.cron__Trigger_Scheduler_1__c = true;
batchRun.cron__Trigger_Scheduler_2__c = false;
} else {
batchRun.cron__Trigger_Scheduler_1__c = false;
batchRun.cron__Trigger_Scheduler_2__c = true;
}

}

}
}