• Ssuazo
  • NEWBIE
  • 0 Points
  • Member since 2010

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

I am new to apex code but have written a trigger that updates a custom revenue field on the opportunity and that works as desired until the opportunity being updated has a close date in the past.  This is due to a validation rule that does fires whenever the close date is less than today.  I see that this is a common issue by searching these boards, but I have not found a solution.  Is there way to writer the validation rule so that it does not fire if a particular field is being updated, or if the update is caused by the trigger?

 

With my limited knowledge, I cannot figure out a way around this error and subsequently no update by the trigger.  I'd really appreciate some ideas on how to manage this issue.  Thanks!

 

This is the validation rule:

 

AND(
OR (
ISPICKVAL(StageName ,"Job Dispatched"),
ISPICKVAL(StageName ,"Waiting for Approval"),
ISPICKVAL(StageName ,"Searching for sub"),
ISPICKVAL(StageName ,"Waiting for Approval"),
ISPICKVAL(StageName ,"Approval Received - Need Contractor"),
ISPICKVAL(StageName ,"Priority - Searching for Sub"),
ISPICKVAL(StageName ,"Proposal/Price Quote")),
CloseDate < TODAY(),
IF(OR(ISNEW(), ISNULL(Id)), if(ConnectionReceivedId =null, TRUE, FALSE),NOT(AND(ISCHANGED(ConnectionReceivedId), NOT(ConnectionReceivedId = null)))),



NOT(Contains($User.Alias, "pnet"))
)

 

 

Hi, this is related to my earlier post here

I have a fairly large test method that gives me 90% test coverage in sandbox with no problems, but then when I try to migrate it to production, I’m suddenly getting an external entry point error on the last line. I talked to my co-worker and she says it’s because there is some inconsistency between sandbox and production, but I can’t seem to figure out how to fix it. I checked all the validation rules and things like that and can’t find any inconsistencies.

Has anyone come across this before? When something works well in sandbox but then you have this sort of trouble getting it into production?
  • March 29, 2010
  • Like
  • 0

I am trying to create an auto number to each Opportunity Line Item within an opportunity. The number will be the Opportunity id number with .001 concetenated at the end. With each subsequent Opportunity Line Item, the number will increase by .001. I am recieving the following error:

 

Error: Compile Error: Illegal assignment from SOBJECT:Opportunity to String at line 9 column 5

 

Below is my trigger.

 

//Loop through all locations and collect the current numbers. trigger ProductNumber on OpportunityLineItem (before insert) { /*Loop every new location you enter*/ for(OpportunityLineItem l:trigger.new) { if(l.Product_Line_Item_ID__c==null){ String cname = l.Opportunity; /* This writes to the debug log*/ //System.debug('location data: '+l); /*This looks up all of the location numbers for the specific account*/ List <OpportunityLineItem> a = [select Product_Line_Item_ID__c from OpportunityLineItem where ACCOUNT__C= :cname ]; /*If the list results are empty*/ system.debug(a); if(a.isEmpty()){ l.OpportunityLineItem=1; }Else { List <Decimal> b = new List<Decimal>(); for (OpportunityLineItem tempLocation:a) { b.add(tempLocation.OpportunityLineItem); } Decimal highest = 0; b.sort(); highest = b[b.size()-1]; l.OpportunityLineItem=highest + 1; } } } }

 

How can I  solve this problem?

Hey guys.
 
I have a Before Update trigger on the Opportunity Object that runs an Apex class which:
 
1. Checks if the Opportunity Status has been changed to a particular stage.
If it has, it then:
2. Checks the Opportunity Products (specifically if there are certain families of products in there)
If Opportunity Products from a specific family (A) are there, without a particular Opportunity Product from another family (B):
3. It automatically works out how much the Opportunity Product from family (B) should cost, given the overall sale cost of the Opportunity
4. Reduces the overall cost of the products of family (A) by the cost of the product from family (B)
5. Updates the Products from Family (A)
6. Inserts the product from Family (B)
 
At the end of the process, the overall Opportunity sale price remains the same, with the new product inserted. It was working a treat, until I added some roll-up formula fields that gather information about the products (An overall sales cost, an overall list price and a formula working out the overall Reduction against List Price)
 
When I tried that, I got the following error:
 
Code:
Apex trigger MyOpportunityUpdate caused an unexpected exception, contact your administrator: 
MyOpportunityUpdate: execution of BeforeUpdate caused by: System.DmlException: Update failed. 
First exception on row 0 with id 00oS0000000KsjwIAC; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, 
Object (id = 006S0000002JnAw) is currently being updated in trigger 
MyOpportunityUpdate: [Id]: Class.MyRFFCreator.CreateRFF: line 35, column 29

 
Interestingly, the error I am getting implies that I've defined a validation formula that's upsetting the system. However, there are no validation rules that get their information from any of the fields being affected by the update. Also, the error arises when I try to update the Opportunity Product from family (A), having reduced it by the appropriate amount.
 
The section of the APEX class that's causing the error is as follows:
Code:
for (OpportunityLineItem cli : FamilyA){
 OpportunityLineItem LineItemToChange = [select id, UnitPrice, Quantity, TotalPrice, (select id, ScheduleDate, Revenue from OpportunityLineItemSchedules order by ScheduleDate asc nulls last limit 1)from OpportunityLineItem where id = :cli.id];
 OpportunityLineItemSchedule LineItemScheduleToChange = LineItemToChange.OpportunityLineItemSchedules;
 LineItemScheduleToChange.Revenue = LineItemScheduleToChange.Revenue - NewRFF.UnitPrice;
 LineItemScheduleToChange.Description = 'This has been auto-edited by Apex';
 update LineItemScheduleToChange; THIS LINE CAUSES THE ERROR           
} 

 I'm really confused.
 
Is the problem that changing a formula field counts as an update, and therefore the trigger is being recursively triggered?
Or that by altering the value of the revenue arising from the Opportunity Product, I'm causing a validation problem with the roll-up field? That would surprise me, as I've been able to add/remove and change Opportunity Products and the Roll-up formula fields deal with it with ease.
 
Or am I just making an obvious error and asking Salesforce/Apex to do something which it isn't able to?
 
Thank you for all your help, in advance. I hope I've been clear enough.
Hello,

I'm trying to create a delete function for a custom object. In my Visualforce code, there's a link that goes to a new page with an object ID query parameter. The controller on that next page gets the id and tries to delete the object. I'm getting this error:

System.Exception: DML currently not allowed

Class.MyDeleteController.<init>: line .., column ..
External entry point

Anyone know why I might be getting this error and how to make this work? I would think that executing a delete function in Apex from Visualforce would be something pretty basic. I've tried executing the function multiple ways, by Id and with the object itself, with code like this:

Id id = ApexPages.currentPage().getParameters().get('id');
delete id;


(Database.delete(id) doesn't work either, same error)

MyObject obj = [select id, Name FROM MyObject__c WHERE id = :id];
delete obj;


(Database.delete(obj) doesn't work either, same error)
 

-paul