• KitagawaSan1337
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Trying to write a trigger to help out with our reporting on lead sources... 

 

The idea is to have upon creation of opportunity, if lead source is not defined, look into the contact. If the contact lead source is null, look at the custom Account_Source__c field. 

 

I have the following written, but am getting an error 

Apex trigger SetOpSource caused an unexpected exception, contact your administrator: SetOpSource: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.SetOpSource: line 6, column 1

 

trigger SetOpSource on Opportunity (after insert,after update) {

//If Opportunity LeadSource = Null and Primary Contact != null then go to Contact Lead Source
for(Opportunity o2:Trigger.new){
if(o2.LeadSource == null && o2.Primary_Contact__r.LeadSource != null){
  o2.LeadSource=o2.Primary_Contact__r.LeadSource;

}else{

//If Opportunity LeadSource = Null and Account.Account_Source__c != null then go to Contact Lead Source
if(o2.LeadSource == null && o2.Account.Account_Source__c != null){
  o2.LeadSource=o2.Account.Account_Source__c;
}
} 
}
}

 

On a side note, I also cant get the trigger to fire based on if statement... can you not use == null on a picklist value?

 

Thanks!

 

I have a trigger to update a custom 'last activity date' when ever a task is marked as closed: 

 

trigger TaskUpdateAccountdate on Task (after insert, after update) {

List<Account> acctToUpdate = new List<Account>();

for(Task tsk : trigger.new)
{if (tsk.IsClosed)
accsToUpdate.add(new Account(Id = tsk.AccountId, Last_Activity_Date__c = Datetime.now()));
}

Update acctToUpdate;
}

 

It was working before, but now I get an error: 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger TaskUpdateAccountdate caused an unexpected exception, contact your administrator: TaskUpdateAccountdate: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001R000000eOkIEIA0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateOpenTaskOwner: maximum trigger depth exceeded Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE]: []: Trigger.TaskUpdateAccountdate: line 10, column 1

 

Not sure what is going on, or why this worked before... 

 

Any ideas? 

 

Thanks!

 

Taking over SFDC for a company who had a text field on the quote called "product quick add" which when a product code is entered, will automatically create the quote line items based on the ';' separated values in the product quick add field. 

 

The issue is that these are being orded alphanumerically based on the product record IDs and not the order they were entered by the user. 

 

Short of changing all the code and forcing the user to set an order, is there any way change the order in which records are inserted from a map? 

 

-Justin 

Trying to write a trigger to help out with our reporting on lead sources... 

 

The idea is to have upon creation of opportunity, if lead source is not defined, look into the contact. If the contact lead source is null, look at the custom Account_Source__c field. 

 

I have the following written, but am getting an error 

Apex trigger SetOpSource caused an unexpected exception, contact your administrator: SetOpSource: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.SetOpSource: line 6, column 1

 

trigger SetOpSource on Opportunity (after insert,after update) {

//If Opportunity LeadSource = Null and Primary Contact != null then go to Contact Lead Source
for(Opportunity o2:Trigger.new){
if(o2.LeadSource == null && o2.Primary_Contact__r.LeadSource != null){
  o2.LeadSource=o2.Primary_Contact__r.LeadSource;

}else{

//If Opportunity LeadSource = Null and Account.Account_Source__c != null then go to Contact Lead Source
if(o2.LeadSource == null && o2.Account.Account_Source__c != null){
  o2.LeadSource=o2.Account.Account_Source__c;
}
} 
}
}

 

On a side note, I also cant get the trigger to fire based on if statement... can you not use == null on a picklist value?

 

Thanks!

 

I have a trigger to update a custom 'last activity date' when ever a task is marked as closed: 

 

trigger TaskUpdateAccountdate on Task (after insert, after update) {

List<Account> acctToUpdate = new List<Account>();

for(Task tsk : trigger.new)
{if (tsk.IsClosed)
accsToUpdate.add(new Account(Id = tsk.AccountId, Last_Activity_Date__c = Datetime.now()));
}

Update acctToUpdate;
}

 

It was working before, but now I get an error: 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger TaskUpdateAccountdate caused an unexpected exception, contact your administrator: TaskUpdateAccountdate: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001R000000eOkIEIA0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateOpenTaskOwner: maximum trigger depth exceeded Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE] Task trigger event AfterUpdate for [00TR000000CVtFR] Account trigger event AfterUpdate for [001R000000eOkIE]: []: Trigger.TaskUpdateAccountdate: line 10, column 1

 

Not sure what is going on, or why this worked before... 

 

Any ideas? 

 

Thanks!

 

Please help in this ASAP. If there is any documents or links available to resolve this issue 

Its very urgent.. Thanks in advance..

 

 

 

Natraj.

 

I got a error message with my Trigger. I just want to do, if Quote's status is ''Accepted', so Opportunity's stage change to 'Closed Won' automaticlly.

 

trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();

for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}

 

Error message,

execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: 0Q09000000009qYCAQ: Trigger.test: line 6, column 38

I have been using SF for a couple of months (Enterprise edition) and am ready to take up Appex classes/triggers. However, I am just now writing my first trigger and, although I have spent countless hours searching through the discussion boards and Google, I can not get this to work.  What I need is a trigger that does the following

 

If Opportunity StageName = '4 - Closed Won' AND Hosting__c is greater than $0

Update Account.Type to Customer

 

Can anyone help guide me in the process?

Hello All

 

my issue is this:

 

In a trigger, i need to retreive the synced quote of an opportunity.

In this trigger i have a query retreiving Opportunities.

When i add the field 'SyncedQuoteId' to the query (and nothing more - no changes to the field or anything)

i get the following exception:

 

Error:Apex trigger Opp1_AfterUpdate caused an unexpected exception, contact your administrator: Opp1_AfterUpdate: execution of AfterUpdate caused by: System.Exception: The opportunity SyncedQuote field is read only within a trigger.: Trigger.Opp1_AfterUpdate: line 58, column 10

 

why do i get this exception just for querying the field?

has someone encountered this and solved it?

 

thanks

NDgani

 

  • March 17, 2010
  • Like
  • 0

Hello All,

I have a trigger that is a bulk update. Sometimes the same object will make it into my update list more than once, which causes the error

 

UpdateParticipationTrigger: execution of AfterInsert caused by: System.ListException: Duplicate id in list: SomeSalesforceIDHere

 

 My list is built using

 

 

Set<Id> ConIds = new Set<Id> {}; for (Payments__c p : payments) { ConIds.add( p.Contact__c ); }

 

 How can I prevent duplicates from making it into that list, and hence causing errors? I am sure it is very simple to do (basically look in the list to see if the ID we are about to add is already in there, if so, don't add it). Let me know. Thanks!