• -d-g-
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi, I'm working with QuoteLineItems. I want custom object fields to update on the Opportunity when the Quote Line Item is synced, and for subsequent changes to each to be updated as well. Whats the best way to accomplish this? It can't be done via workflow.  Is this possible to do through apex trigger(s)? Thanks for any guidance.

 

-david

  • March 27, 2013
  • Like
  • 0

So, I've got a couple of triggers that work well when working directly from tasks or events.  An issue has arisen though, where the triggers are causing this: System.ListException: List index out of bounds: 0 when someone tries to Convert a Lead.  Here is the offending code:

 

Id WhoIDCheck = trigger.new[0].WhoId;

List<Event> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];

 

The trigger is a Before Update trigger, I am thinking about converting the trigger to an After Update, but I really don't understand how the whole process of converting a lead works (what happens to the ID over the course of the process, it seems to be changed, but when?), so I don't know if that will work.  Any suggestions/help would be greatly appreciated.

  • November 07, 2012
  • Like
  • 0

So, I am getting this:

Error: Invalid Data.
TasksOutlookTaskUpdate: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0: Trigger.TasksOutlookTaskUpdate: line 7, column 1 ...

... when I try to use certain accounts/contacts/opportunities.  It seems like accounts/contacts/opportunities created before a certain hour today, show up in the query making the trigger function; but after a certain time today, there is nothing but failure.  I've tried to mess around with it, but have come up with nothing ... any help would be appreciated!

Here's the code:

trigger TasksOutlookTaskUpdate on Task (before insert, before update) {
    String TaskType = trigger.new[0].Type;
    Id WhoIDCheck = trigger.new[0].WhoId;
    Id WhatIDCheck = trigger.new[0].WhatId;
    List<Task> RefName = [SELECT What.Type, What.Name FROM Task WHERE WhatId = :WhatIDCheck];
    List<Task> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];
    If ( WhoNum[0].Who.Type == 'Contact' ) {
        List<Contact> ContData = [SELECT Name, Phone, Email FROM Contact WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + ContData[0].Name + '\n' + 'Phone: ' + ContData[0].Phone + '\n' + 'Email: ' + ContData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    } else if ( WhoNum[0].Who.Type == 'Lead' ) {
        List<Lead> LeadData = [SELECT Name, Phone, Email FROM Lead WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + LeadData[0].Name + '\n' + 'Phone: ' + LeadData[0].Phone + '\n' + 'Email: ' + LeadData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID;
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    }
}

thanks!

  • October 22, 2012
  • Like
  • 0

So, someone wants a custom, required field, in the case object.  Unfortunately, this breaks classes in multiple managed apps ... which means I can't add custom code until these issues are fixed.  Is there a way to alter the classes of the managed apps to fix the problem?  So far, everything seems to say "no".  It would be nice to have a human opinion on this (sorry google).  Thanks.

 

-dg

  • September 03, 2012
  • Like
  • 0

Hi, I'm having problem with test code: I am getting Assertion Failures when I try to deploy it.  I have tried to disable all field validations and workflows on the system while I attempt to deploy it, but its not working.  Today I was looking at "Field Updates" and there are some formulas that could affect the fields that the code is  working with.  My question is: if I have disabled the Field Updates associated workflow, are these updates still happening?  What can I do to temporarily disable them while I put my code on the system, or do I need to code around them?  Any explanation, would be great, thanks!

 

-dg

  • August 29, 2012
  • Like
  • 0

I am running into what seems like a common problem with Milestones.  Someone installed the unmanaged version of PM+ 1.53 a while back and when I was trying to upload new code to the system, tests for milestones failed - preventing me from doing anything.  I decided the best route to take was to upgrade PM+, using the Eclipse IDE.  I have had to make a bunch of changes to the test code for the system.  I am turning off all the validation fields and workflows when trying to deploy the code, and am now down to one error:

"System.AssertException: Assertion Failed"..."Class.Milestone1_Test_Field_Values.testFieldValues: Line 372...".  I'm at a loss, I've checked what I think is every dependency and whatnot ...

 

Any advice you can give me? It would be much appreciated.

  • August 28, 2012
  • Like
  • 0

Before I came on the scene, someone installed Milestones PM in an Unmanaged form on the production system.  It works fine, but during the system checks that occur when trying to upload new code to production, the tests fail.  Anyway, I read that upgrading the package solves this issue.  Unfortunately I can't find any information about how to go about upgrading an unmanaged package.  Here are some questions:

 

If I uninstall the package, will I lose the data?  This is a big one.

If I uninstall the package, what will happen to the validation rules and the workflows?

What is the best way to go about uninstalling and reinstalling the package?  Ensuring that I don't lose data and hopefully workflow and other rules.

 

Thanks for any clarification, tips, or whatever...

  • July 18, 2012
  • Like
  • 0

I am getting an exception because one of my queries is not returning results, I'm not sure why, can you take a look?

This is the line that's causing the problem: List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

 

Here's the rest of the code, if that helps.  Thanks!

 

trigger SyncdQuoteUpdate onMilestone1_Project__c (beforeinsert, beforeupdate) {

Id INVLI = trigger.new[0].Invoice_Line_Item__c;

String SyncedQuote = trigger.new[0].Synced_Quote__c;

Date breakdate = Date.newinstance(2012, 7, 8);

Date CreationDate = trigger.new[0].Created_Date__c;

System.Debug(INVLI);

List<QuoteLineItem> quotelid = [SELECT QuoteId FROM QuoteLineItem WHERE Id = :INVLI];

List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

if ( CreationDate > breakdate ) {

if (SyncedQuote == null) {

trigger.new[0].Synced_Quote__c = Synced[0].Id;

}

}

}

  • July 10, 2012
  • Like
  • 0

Hi everyone, I'm new to the world of apex and such and I'm working on my first test class.  So far I have managed to get most of the code working, but now I'm stuck, and no amount of googling is solving the problem, so any input would be appreciated, I'm sure this is an easy fix for people here.

 

I'm getting this error in Eclipse: "Invalid Initial Expression Type for Field Quote.OpportunityID, Expecting: Id."  It is coming from this block of code:

 

Quote quo = new Quote

            (Name = 'Superstar', OpportunityID = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend']);

         insert quo;

 

I'm at a loss.  Any input would be helpful.  Here's the rest of the code if that would help any:

 

@isTest

private class PFIFillTest {

 

    static testMethod void myUnitTest() {

    Account acc = newAccount

    (Name = 'TestCo');

    insert acc;

         Opportunity opp = newOpportunity

            (Name = 'WillitBlend', Account = [SELECT Id, Name FROM Account Where Name = 'TestCo'], 

            StageName = 'Proposal/Price Quote', CloseDate = Date.today(),

            ForecastCategoryName = 'Best Case');

         insert opp;

         Quote quo = new Quote

            (Name = 'Superstar', OpportunityID = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend']);

         insert quo;

         QuoteLineItem qli = newQuoteLineItem

         (UnitPrice = 2500, Quantity = 1, Description = 'Wahoo');

         insert qli;

       Test.startTest();

       update qli;

       Test.stopTest();

qli = [SELECT id, Project_For_Invoicing__c FROM QuoteLineItem WHERE Description = 'Wahoo'];

       system.assert(qli.Project_For_Invoicing__c != null);

    }

}

  • June 20, 2012
  • Like
  • 0

So, I've got a couple of triggers that work well when working directly from tasks or events.  An issue has arisen though, where the triggers are causing this: System.ListException: List index out of bounds: 0 when someone tries to Convert a Lead.  Here is the offending code:

 

Id WhoIDCheck = trigger.new[0].WhoId;

List<Event> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];

 

The trigger is a Before Update trigger, I am thinking about converting the trigger to an After Update, but I really don't understand how the whole process of converting a lead works (what happens to the ID over the course of the process, it seems to be changed, but when?), so I don't know if that will work.  Any suggestions/help would be greatly appreciated.

  • November 07, 2012
  • Like
  • 0

So, I am getting this:

Error: Invalid Data.
TasksOutlookTaskUpdate: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0: Trigger.TasksOutlookTaskUpdate: line 7, column 1 ...

... when I try to use certain accounts/contacts/opportunities.  It seems like accounts/contacts/opportunities created before a certain hour today, show up in the query making the trigger function; but after a certain time today, there is nothing but failure.  I've tried to mess around with it, but have come up with nothing ... any help would be appreciated!

Here's the code:

trigger TasksOutlookTaskUpdate on Task (before insert, before update) {
    String TaskType = trigger.new[0].Type;
    Id WhoIDCheck = trigger.new[0].WhoId;
    Id WhatIDCheck = trigger.new[0].WhatId;
    List<Task> RefName = [SELECT What.Type, What.Name FROM Task WHERE WhatId = :WhatIDCheck];
    List<Task> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];
    If ( WhoNum[0].Who.Type == 'Contact' ) {
        List<Contact> ContData = [SELECT Name, Phone, Email FROM Contact WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + ContData[0].Name + '\n' + 'Phone: ' + ContData[0].Phone + '\n' + 'Email: ' + ContData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    } else if ( WhoNum[0].Who.Type == 'Lead' ) {
        List<Lead> LeadData = [SELECT Name, Phone, Email FROM Lead WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + LeadData[0].Name + '\n' + 'Phone: ' + LeadData[0].Phone + '\n' + 'Email: ' + LeadData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID;
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    }
}

thanks!

  • October 22, 2012
  • Like
  • 0

I am getting an exception because one of my queries is not returning results, I'm not sure why, can you take a look?

This is the line that's causing the problem: List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

 

Here's the rest of the code, if that helps.  Thanks!

 

trigger SyncdQuoteUpdate onMilestone1_Project__c (beforeinsert, beforeupdate) {

Id INVLI = trigger.new[0].Invoice_Line_Item__c;

String SyncedQuote = trigger.new[0].Synced_Quote__c;

Date breakdate = Date.newinstance(2012, 7, 8);

Date CreationDate = trigger.new[0].Created_Date__c;

System.Debug(INVLI);

List<QuoteLineItem> quotelid = [SELECT QuoteId FROM QuoteLineItem WHERE Id = :INVLI];

List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

if ( CreationDate > breakdate ) {

if (SyncedQuote == null) {

trigger.new[0].Synced_Quote__c = Synced[0].Id;

}

}

}

  • July 10, 2012
  • Like
  • 0