• majo
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 7
    Replies

hi,

I'm trying to create a test class for a trigger:

 

trigger deleteTask on OpportunityLineItem (before delete) {

List<OpportunityLineItem> OppLIs = Trigger.old;
List<Task> tasks = new List<Task>();

for (OpportunityLineItem OppLI : OppLIs) {

Opportunity Opp = [ Select OwnerId from Opportunity where id=:OppLI.OpportunityId limit 1 ];
User usuario = [ Select Sociedad__c from User where id=:Opp.OwnerId ];

//el usuario debe pertenecer a argentina = usuario.Sociedad__c == 1000
if ( usuario.Sociedad__c == '1000' ) {
tasks = [ Select Id from Task where whatID=:OppLI.OpportunityId and Subject='Recordatorio: Vencimiento de producto'];
}
}

delete tasks;

}

 

My test class is:

 

@isTest
private class deleteTaskTest {

static testMethod void myUnitTest() {

//Create a custom pricebook
Pricebook2 pb = new Pricebook2(Name='Custom Pricebok',IsActive=true);
insert pb;

// Create a new product
Product2 prod = new Product2(IsActive=true, Name='Product');
insert prod;

// Create a pricebook entry for custom pricebook
PricebookEntry pbe2 = new PricebookEntry(Pricebook2Id=pb.Id, Product2Id=prod.Id,
IsActive=true, CurrencyIsoCode='ARS', UnitPrice=100,

  UseStandardPrice=false);

insert pbe2;

test.startTest();

delete prod;

test.stopTest();

}
}

 


When I run this test class, I get this error message:

 

 Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []

 

In the line: insert pbe2;

 

 Can someone understand why this is happening? Thanks!

  • December 07, 2009
  • Like
  • 0

Hi!

I have to develop a new functionality that creates a new task for every Contact that hasn't been contact in a while.

So, I've been investigating differents possibilities on how to proced and I found "Batch Apex".

I know I have to create a class that has 3 methods: start, execute and finish. After that I have to create an instance of that class and execute it. But I don't understan where and how I can make the process to run automatically in a period of time.

Could someone help me? Or add a link with a simple example? 

Thanks very much!

Majo :smileyvery-happy:

  • November 05, 2009
  • Like
  • 0

Hi!

I've created a trigger to create a task everytime someone creates an Opportunity's product. But I have a problem, the trigger creates the task twice! I couldn't find yet the problem. Could someone tell what's wrong in the code?

Thanks! :smileyhappy:

 

trigger createTask2 on OpportunityLineItem (before insert, before update) {

    List<Task> tasks = new List<Task>();
    List<OpportunityLineItem> OppLIs = Trigger.new;
    
    for (OpportunityLineItem OppLI : OppLIs) {
        
        //Obtengo el Id del usuario que creo la oportunidad
        Opportunity Opp = [ Select OwnerId from Opportunity where id=:OppLI.OpportunityId limit 1 ];
        
        //User usuario = [ Select Name from ]

        //Obtengo el día que se vence el producto
        Date diaVenc = OppLI.Fecha_de_vencimiento__c;
        Datetime dhReminder = datetime.newInstance(diaVenc.year(), diaVenc.month(),diaVenc.day());
        dhReminder.addHours(10);



        Task tsk = new Task(whatID = OppLI.OpportunityId, 
                            Ownerid = Opp.OwnerId, 
                            Subject = 'test', 
                            ActivityDate = diaVenc,
                            IsReminderSet = true,
                            ReminderDateTime = dhReminder );
        tasks.add(tsk);
        
    }
    
    insert tasks;
}
 

 

 

  • October 22, 2009
  • Like
  • 0

Hello,

 

I'm new at developing in salesforce.com , so I'm having a little trubble to finding out some things.

 

First of all, I would like to write a trigger for the Opportunity. I want to create automatically a new task, when ever a user creates a new Opportunity.

 

trigger createTask on Opportunity (before insert, before update){

        List<Task> task = new List<Task>();
        
        for (Integer i = 0; i < Trigger.new.size(); i++) {
        
            task.add(new Task(
                         whatid=Trigger.new[i].Id,
                         OwnerId=Trigger.new[i].OwnerId,
                         Subject='First Contact '
                   ) ) ;

        }
        
        insert task;

}
 

My idea for this trigger, is to create a task for each new Opportunity created. Is it right?

thanks!

 

 

 

Message Edited by majo on 10-16-2009 08:52 AM
Message Edited by majo on 10-16-2009 08:53 AM
  • October 15, 2009
  • Like
  • 0

Hi!

I've created a trigger to create a task everytime someone creates an Opportunity's product. But I have a problem, the trigger creates the task twice! I couldn't find yet the problem. Could someone tell what's wrong in the code?

Thanks! :smileyhappy:

 

trigger createTask2 on OpportunityLineItem (before insert, before update) {

    List<Task> tasks = new List<Task>();
    List<OpportunityLineItem> OppLIs = Trigger.new;
    
    for (OpportunityLineItem OppLI : OppLIs) {
        
        //Obtengo el Id del usuario que creo la oportunidad
        Opportunity Opp = [ Select OwnerId from Opportunity where id=:OppLI.OpportunityId limit 1 ];
        
        //User usuario = [ Select Name from ]

        //Obtengo el día que se vence el producto
        Date diaVenc = OppLI.Fecha_de_vencimiento__c;
        Datetime dhReminder = datetime.newInstance(diaVenc.year(), diaVenc.month(),diaVenc.day());
        dhReminder.addHours(10);



        Task tsk = new Task(whatID = OppLI.OpportunityId, 
                            Ownerid = Opp.OwnerId, 
                            Subject = 'test', 
                            ActivityDate = diaVenc,
                            IsReminderSet = true,
                            ReminderDateTime = dhReminder );
        tasks.add(tsk);
        
    }
    
    insert tasks;
}
 

 

 

  • October 22, 2009
  • Like
  • 0

Hello,

 

I'm new at developing in salesforce.com , so I'm having a little trubble to finding out some things.

 

First of all, I would like to write a trigger for the Opportunity. I want to create automatically a new task, when ever a user creates a new Opportunity.

 

trigger createTask on Opportunity (before insert, before update){

        List<Task> task = new List<Task>();
        
        for (Integer i = 0; i < Trigger.new.size(); i++) {
        
            task.add(new Task(
                         whatid=Trigger.new[i].Id,
                         OwnerId=Trigger.new[i].OwnerId,
                         Subject='First Contact '
                   ) ) ;

        }
        
        insert task;

}
 

My idea for this trigger, is to create a task for each new Opportunity created. Is it right?

thanks!

 

 

 

Message Edited by majo on 10-16-2009 08:52 AM
Message Edited by majo on 10-16-2009 08:53 AM
  • October 15, 2009
  • Like
  • 0

Below is a very simple batch class but it is failing as soon as it starts to execute.

global class batchTest implements Database.Batchable<SObject>{

global database.querylocator start(Database.BatchableContext bc){
return Database.getQueryLocator('select Id, Name from Account where Name = \'batchTesting\'');
}

global void execute(Database.BatchableContext bc, sObject[] objects){
List<Account> accns = new List<Account>();
for(sObject s : objects){
Account a = (Account)s;
a.Description = 'batch testing. blah blah blah. ' + system.now();
accns.add(a);
}
update accns;
}

global void finish(Database.BatchableContext bc){
system.debug('all done.');
}
}

Here is the error:

Apex script unhandled exception by user/organization: 00550000000wOce/00DQ00000009Pxq Source organization: 00D00000000hXqv (null) Failed to process batch for class 'batchTest'

Debug Log:
20090930224059.163:External entry point: returning Database.QueryLocator from method global Database.QueryLocator start(Database.BatchableContext) in 0 ms
20090930224059.163:Class.batchTest.start: line 4, column 16: SOQL locator query with 10001 rows finished in 183 ms

 

Does anybody see anything glaringly wrong? I've basically copy and pasted this from the Developer Guide. One thing that seems wrong is that it says the query locator returns 10001 records, it should be 30,000.

 

I am trying to initiate this from the debug log with the following code:

batchTest job = new batchTest();
ID batchprocessid = Database.executeBatch(job);
system.debug(batchprocessid);

I'm not sure if this makes a difference, but worth noting.


 

Thanks,

Jason

Message Edited by TehNrd on 10-01-2009 04:14 PM
  • September 30, 2009
  • Like
  • 0