• edward scott 10
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 11
    Replies
I have a visualforce page that works perfectly on a computer and like 90 percent on mobile. My problem is there are two fields that start an application for a new member that don't work on mobile. The first is a picklist and the second is a dependent picklist. There is also a third picklist on the page and that one works fine. Is there any reason why the first two might not be working? 
Hi All,

I am trying to write a SOQL statement on the account object that will select all opportunities that it is associtated through a custom look up field named "Referring Facility" on the opportunity to the account. I would like to be able to sum the amount of all of those opportunities. Right now I have this working through a junction object but I am trying to get rid of those. 

I was able to figure out how to write a trigger to do the same thing on the contact using a trigger that looks down at the contact roles takes the contact id of the referring therapist. But I am struggling to write the SOQL statement upwards from the opportunity to the account through the custom field. The closet I got it to work was to get one opportunity to write its into to the account but it wouldn't sum. 

Also, I am open to advice on the best way to do this. Ideally it would be nice if this happened when the opportunity closed and would update the account without having to press edit on the account to see the new value.

Thanks in advance for your help,
Edward
Hi All,
 
I am trying to rollup opportunity amounts to a contact record if they are attached to an opportunity as a contactrole with the role of 'referring therapist'. I have gotten pretty far with the code. Currently when I edit an opportunity everything work and the fields that I created on the contact get updated. The main problem I am having now is this trigger fires even when there isn't a contact role attached to the opportunity and when that happens I recieve an error message that says:

ContactRoleRollup: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.ContactRoleRollup: line 16, column 1

I know this is because it is trying to run on every opportunity but what I dont know is how to fix it. 

Any help would be greatly appreciated. I am posting the code below. Thanks in advance for your help.
 
trigger ContactRoleRollup on Opportunity (after insert, after update)
{

    List<Contact> cwOpsToUpdate = new List<Contact>();
     List<Id>ocrIds = new List<Id>();
   {

     
     for(Opportunity ocr: Trigger.New) {
         ocrIds.add(ocr.Id);
         }



 //Must use the colon that specifies the bind variable. This query pulls one row from the Opportunity contact role table. I will use the contact id from this record.
         OpportunityContactRole test2 = [SELECT Id, OpportunityId, ContactId, Role FROM OpportunityContactRole WHERE OpportunityId = :ocrIds AND Role = 'Referring Therapist'];
         

//Create a list of opportunities who are children of this contact record.

List<Opportunity> opp = [Select Opportunity.Id, Opportunity.Amount, Opportunity.Net_Amount__c, Opportunity.Amount_Returned__c, 
Opportunity.CloseDate From Opportunity Where Opportunity.Id IN (Select OpportunityContactRole.OpportunityId from OpportunityContactRole where 
OpportunityContactRole.ContactId = :test2.ContactId) ORDER BY Opportunity.CloseDate ASC];
 
Double totalReferrals = 0;
Double netReferrals = 0;
Double totalReturns = 0;
Date minCloseDate = opp[0].CloseDate;
Integer oppListSize = opp.size();


List<Opportunity> oppDSC = [Select Opportunity.Id, Opportunity.Amount, Opportunity.Net_Amount__c, Opportunity.Amount_Returned__c, 
Opportunity.CloseDate From Opportunity Where Opportunity.Id IN (Select OpportunityContactRole.OpportunityId from OpportunityContactRole where 
OpportunityContactRole.ContactId = :test2.ContactId) ORDER BY Opportunity.CloseDate DESC];

Date maxCloseDate = oppDSC[0].CloseDate;

// Loop through the filtered opportunites and sum up their amounts.

    for(Opportunity op : opp)
    {
     If (op.Amount != Null)
     {
      totalReferrals += op.Amount;
      netReferrals += op.Net_Amount__c;
      totalReturns += op.Amount_Returned__c;
     }
    }

//Place the summed total in a custom field on the associated contact record.

Contact test3 = [SELECT Id, Total_Amount_Of_Referrals__c, Total_Amount_Of_Returns__c, Net_Amount__c, First_Referral_Date__c FROM Contact WHERE Id = :test2.ContactId];
test3.Total_Amount_Of_Referrals__c = totalReferrals;
test3.Total_Amount_Of_Returns__c = totalReturns;
test3.Net_Amount__c = netReferrals;
test3.First_Referral_Date__c = minCloseDate;
test3.Last_Referral_Date__c = maxCloseDate;
test3.Referral_Opportunity_Count__c = oppListSize;
cwOpsToUpdate.add(test3);

}

if(cwOpsToUpdate.size()>0){
update cwOpsToUpdate;
}
}

 
Hi All,

I am trying to write some opportunity information from the opportunity to a contact that is listed as a contact role on an opportunity. I found this trigger and was able to update it to do most of what I need it to do. Currently, I am able to sum three opportunity amount fields to custom fields on the contact. 

What I need help with is being able to write the first opportunity close date which would be the furthest opportunity date in the past and then the last opportunity closed date. The second thing is being able to count the number of opportunities that the contact is on. And the last thing is bullying the trigger.

I am posting my current code below and any help would be greatly appreciated. 
 
trigger ContactRoleRollup on Opportunity (after insert, after update)
{

     Integer i = 0;

          // List the associated opportunities ID
          String intTest = Trigger.new[i].Id;

 //Must use the colon that specifies the bind variable. This query pulls one row from the Opportunity contact role table. I will use the contact id from this record.
         OpportunityContactRole test2 = [SELECT Id, OpportunityId, ContactId, Role FROM OpportunityContactRole WHERE OpportunityId = :intTest AND Role = 'Referring Therapist'];

//Create a list of opportunities who are children of this contact record.

List<Opportunity> opp = [Select Opportunity.Id, Opportunity.Amount, Opportunity.Net_Amount__c, Opportunity.Amount_Returned__c From Opportunity Where Opportunity.Id IN (Select OpportunityContactRole.OpportunityId from OpportunityContactRole where OpportunityContactRole.ContactId = :test2.ContactId)];
 
Double totalReferrals = 0;
Double netReferrals = 0;
Double totalReturns = 0;

// Loop through the filtered opportunites and sum up their amounts.

    for(Opportunity op : opp)
    {
     If (op.Amount != Null)
     {
      totalReferrals += op.Amount;
      netReferrals += op.Net_Amount__c;
      totalReturns += op.Amount_Returned__c;
     }
    }

//Place the summed total in a custom field on the associated contact record.

 Contact test3 = [SELECT Id, Total_Amount_Of_Referrals__c, Total_Amount_Of_Returns__c, Net_Amount__c FROM Contact WHERE Id = :test2.ContactId];
test3.Total_Amount_Of_Referrals__c = totalReferrals;
test3.Total_Amount_Of_Returns__c = totalReturns;
test3.Net_Amount__c = netReferrals;

//Do all this when the trigger is initiated.

update test3;
 

}

Thanks in advance for your help,
Ed 
Hi all,

I am trying to write information from the opportunitylineitem to the opportunity. On the LineItem there is a field called Product which is a standard lookup field to the product object. I am trying to get that name to go from the LineItem to the Opportunity to a custom field called product. When I was trying to reference the Standard lookup product I kept getting an error message saying it wasn't a field so changed it to the description to see if i could get the description to go from the LineItem to the Opportunity. The trigger did save but it didn't work so I wanted to post my code here to see if anyone could help.

So my first question is how do I reference a standard lookup field in apex and the second is this the best way to get information from the LineItem to the opportunity?
 
trigger OpportunityProductTrigger on OpportunityLineItem (after update) {

List<Id> oppIds = new List<Id>();
String Item;

    if(trigger.isAfter) {
        for (OpportunityLineItem oli: trigger.new){
            oppIds.add(oli.opportunityID);
        }
        List<OpportunityLineItem> allOLI = [SELECT id, ProductCode FROM OpportunityLineItem WHERE OpportunityId in: oppids];
        List<Opportunity> oppsToUpdate = [SELECT id, Product__c FROM Opportunity WHERE id in: oppids];
        if(allOLI.size() > 0){
          for(OpportunityLineItem allOLI2: allOLI){
                    Item = allOLI2.ProductCode;
                }//END if(allOLI2.Number_of_Months__c > contractLengthMonths)
            } //END for(OpportunityLineItem allOLI2: allOLI)
            for(Opportunity oppUpdate: oppsToUpdate){
                oppUpdate.Product__c = Item;
            }// END for(Opportunity oppUpdate: oppsToUpdate)
 
        }

}

Thanks for your help,
Ed
Hi,
I am trying to convert a trigger I wrote into an apex class and call the class from the trigger. I am receiving two errors when I copy the code into the class. I am hoping that someone on here can help me or give me a few pointers on what I can do to fix the problem. This is the trigger that fires correctly as a trigger.
trigger RunAssignmentRule on Lead (after update) {
    List<Lead> ls = new List<Lead>();

    for (Lead l : Trigger.new) {
    
    String oldVal = trigger.oldMap.get(l.id).Status;
    
        if (l.Status == 'Open/Requalified' && oldVal <> 'Open/Requalified') {
            ls.add(new Lead(id = l.id));
        }
    }
    
    if (ls.size() > 0) {
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;
    Database.update(ls, dmo);
}

}

The trigger makes a lead run back through the lead assignment when its status his open requalified. When I add it to an apen class I get two errors. An unexpected token error on the list and an error on for because it says it expected a } instead of the for. 

Thanks for your help,
Edward

 
Hi,

I am trying to figure out two things. One if I have a class that is completely commented out to inactivate the class does that class still count against my code coverage. The second question is how do I make changes to code when my coverage is below 75 percent and I can't deploy any code. And I guess a third question can test code be deployed when the coverage is below 75 percent?

Thanks for your help,
Ed
Hi All,

I am trying to write some opportunity information from the opportunity to a contact that is listed as a contact role on an opportunity. I found this trigger and was able to update it to do most of what I need it to do. Currently, I am able to sum three opportunity amount fields to custom fields on the contact. 

What I need help with is being able to write the first opportunity close date which would be the furthest opportunity date in the past and then the last opportunity closed date. The second thing is being able to count the number of opportunities that the contact is on. And the last thing is bullying the trigger.

I am posting my current code below and any help would be greatly appreciated. 
 
trigger ContactRoleRollup on Opportunity (after insert, after update)
{

     Integer i = 0;

          // List the associated opportunities ID
          String intTest = Trigger.new[i].Id;

 //Must use the colon that specifies the bind variable. This query pulls one row from the Opportunity contact role table. I will use the contact id from this record.
         OpportunityContactRole test2 = [SELECT Id, OpportunityId, ContactId, Role FROM OpportunityContactRole WHERE OpportunityId = :intTest AND Role = 'Referring Therapist'];

//Create a list of opportunities who are children of this contact record.

List<Opportunity> opp = [Select Opportunity.Id, Opportunity.Amount, Opportunity.Net_Amount__c, Opportunity.Amount_Returned__c From Opportunity Where Opportunity.Id IN (Select OpportunityContactRole.OpportunityId from OpportunityContactRole where OpportunityContactRole.ContactId = :test2.ContactId)];
 
Double totalReferrals = 0;
Double netReferrals = 0;
Double totalReturns = 0;

// Loop through the filtered opportunites and sum up their amounts.

    for(Opportunity op : opp)
    {
     If (op.Amount != Null)
     {
      totalReferrals += op.Amount;
      netReferrals += op.Net_Amount__c;
      totalReturns += op.Amount_Returned__c;
     }
    }

//Place the summed total in a custom field on the associated contact record.

 Contact test3 = [SELECT Id, Total_Amount_Of_Referrals__c, Total_Amount_Of_Returns__c, Net_Amount__c FROM Contact WHERE Id = :test2.ContactId];
test3.Total_Amount_Of_Referrals__c = totalReferrals;
test3.Total_Amount_Of_Returns__c = totalReturns;
test3.Net_Amount__c = netReferrals;

//Do all this when the trigger is initiated.

update test3;
 

}

Thanks in advance for your help,
Ed 
Hi all,

I am trying to write information from the opportunitylineitem to the opportunity. On the LineItem there is a field called Product which is a standard lookup field to the product object. I am trying to get that name to go from the LineItem to the Opportunity to a custom field called product. When I was trying to reference the Standard lookup product I kept getting an error message saying it wasn't a field so changed it to the description to see if i could get the description to go from the LineItem to the Opportunity. The trigger did save but it didn't work so I wanted to post my code here to see if anyone could help.

So my first question is how do I reference a standard lookup field in apex and the second is this the best way to get information from the LineItem to the opportunity?
 
trigger OpportunityProductTrigger on OpportunityLineItem (after update) {

List<Id> oppIds = new List<Id>();
String Item;

    if(trigger.isAfter) {
        for (OpportunityLineItem oli: trigger.new){
            oppIds.add(oli.opportunityID);
        }
        List<OpportunityLineItem> allOLI = [SELECT id, ProductCode FROM OpportunityLineItem WHERE OpportunityId in: oppids];
        List<Opportunity> oppsToUpdate = [SELECT id, Product__c FROM Opportunity WHERE id in: oppids];
        if(allOLI.size() > 0){
          for(OpportunityLineItem allOLI2: allOLI){
                    Item = allOLI2.ProductCode;
                }//END if(allOLI2.Number_of_Months__c > contractLengthMonths)
            } //END for(OpportunityLineItem allOLI2: allOLI)
            for(Opportunity oppUpdate: oppsToUpdate){
                oppUpdate.Product__c = Item;
            }// END for(Opportunity oppUpdate: oppsToUpdate)
 
        }

}

Thanks for your help,
Ed
Hi,

I am trying to figure out two things. One if I have a class that is completely commented out to inactivate the class does that class still count against my code coverage. The second question is how do I make changes to code when my coverage is below 75 percent and I can't deploy any code. And I guess a third question can test code be deployed when the coverage is below 75 percent?

Thanks for your help,
Ed
Hi,
 
In formulas you can use ISCHANGED function. Is there a similar method in Apex or is there some recommended design pattern for checking if a field value has changed in after update event?
 
How about ISNEW function?
 
Thanks!
  • November 28, 2008
  • Like
  • 0