• DannyTK
  • NEWBIE
  • 95 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 28
    Replies
Hi all,

Receiving the test coverage error, yet the test class covers 100% of the trigger, and across the org when Estimating the code coverage it's giving me 80%.  Can someone inform me of where the gap is, not sure exactly why it's stating that it's not covered when all tests shows otherwise?

-d
Hello all, 

I'm trying to write a simple trigger to update new cases created by Process Builder (so assignment rules can re-assign, since these cases hit the rules until it's Edited and Saved manually).  So all the trigger would have to do is re-save the cases (with nothing else to change).  

what i have is: 

trigger caseUpdate on Case (after insert) {
    List<Id> idCase = new List<Id>{};
        for (Case ticket : Trigger.new) 
    update ticket;
  }

But this doesn't seem to work.  Can someone take a look and see where I went wrong?

thanks again community
-danny
Good afternoon, 

I'm working on a simple trigger that can save new cases generated by Process Builder in order for them to hit the assignment rules (Cases created via Process builder will not hit the assignment rules until the Case is Edited and Saved again), and have the following:

trigger caseUpdate on Case (after insert) {
List <Case> newCases = new List <Case>();
    for (Case ticket : Trigger.new) {
        ticket.Status = 'Pending Customer Information';        
    }
    update newCases;
    }

Can someone take a look to see if I missed anything, i'm not a developer so wanted to get a more experience eye on this to validate that it looks okay. 

Thanks community
-danny
Good morning everyone,  

I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity.  The trigger works okay, but i'm having trouble with my test class.  I'm receiving the Expression error when trying to save.  I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:

Trigger is:

trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
      Set<String> locationSet = new Set<String>();
      Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c)){
              locationSet.add(obj.Location__c);
          }
      }
      if(!locationSet.isEmpty()){
          for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
              mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
          }
      }
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
                  obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
        }
          else{
              obj.Data_Center_Location__c = null;
          }
      }
  }

________
Again, the trigger works as should, the test class on the other hand doesn't:

@isTest

    Private class UpdateDataCenterLocationTestClass {
        static testMethod void UpdateDataCenterLocation () {
    
        List <Opportunity> OpportunityLst = new List <Opportunity>();
        Opportunity Opp = new Opportunity ();
       Opportunity.Name = 'test Opportunity';
       Opportunity.Location__c = 'TX-DAL-03LEW' ;
       Opportunity.Stagename = 'Stage 1: Qualified Prospect';
       
       Opportunity.Closedate = '2015, 2, 26';
        OpportunityLst.add(opp);
        
        insert Opp;
    
    }
    }

--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough.  Any guidance would be much appreciated.

Thanks everyone
-d
Good afternoon,

I'm having an issue with getting proper coverage on test class (i'm not a developer).  The trigger is to bring down a field value to a custom field on an event (event field 'Fortune_1000_Ranking__c') from the related Contact record on the event.  The field originates from the Account and is a formula field on the Contact record ('Fortune_1000_2013_Ranking__c').  the trigger seems to work fine:

trigger UpdateEventFortune1000 on Event (before insert, before update) {
Set<Id>CIds = new Set<Id>();for (Event E:trigger.new)
{String wId = e.WhoId; If(wID!=null && wId.startsWith('003')&& !cIds.contains(e.WhoId))
{cIds.add(e.WhoId);}}
    
    List<Contact> EventC = [Select Id, Fortune_1000_2013_Ranking__c from Contact where
                            Id in :cIds];
    
    Map<Id, Contact> CMap = new Map<Id, Contact>(); for (Contact c: EventC)
        
    {CMap.put(c.Id,c);}
    
    for (Event e:trigger.new)
    {String wId = e.WhoId; if (wId!=null && wId.startswith('003'))
    {Contact thisC = cMap.get(e.WhoId);
    if(thisC!=null)
    {e.Fortune_1000_Ranking__c = thisC.Fortune_1000_2013_Ranking__c;}}}
 }

Yet i'm having issues with the Test class and getting proper coverage:
@isTest
private class UpdateEventFortune1000testclass {
    
static testMethod void UpdateEventFortune1000 () {
 
   
List<Account>Account = new List<Account> {new Account (
    name = 'test company',
    Fortune_1000_2013_Ranking__c = 1,
    phone = '(555) 555-5555') };
    insert Account;

List<Contact>Contact = new List<Contact> {new Contact (
    firstname = 'test',
    lastname = 'testtest',
    phone = '(555) 555-5555') };    
    insert Contact;
    
List<Event> e = new List<Event> {new Event(
    WhoID = Contact[0].id,
    subject = 'test trigger',
    Type = 'Meeting')};
    
    insert e;
    
List<Event> Eventstoupdate = New List<event>{[select id from event where id in :e]};
    for (event eok:eventstoupdate);
    
    update eventstoupdate;
    
Contact[] c = [select id,Fortune_1000_2013_Ranking__c from Contact where id in :Contact];
    System.assertEquals(1,Contact[0].Fortune_1000_2013_Ranking__c);
    
}
}

Can someone take a look at the test class and see what is wrong with it, i'm not experienced enough on the development side to really see where the error lies.

-d
Good evening, 

need help getting the proper test coverage on trigger, and one issue i'm having with the test class is the field that i'm actually trying to test.  the trigger is to populate an Event record custom field ('Fortune_1000_Ranking__c') from a field pulled from the related Contact ('Fortune_1000_2013_Ranking__c'), which is actually a forrmula field pulled from the same field on the Account record (master-detail).  The trigger works fine:

trigger UpdateEventFortune1000 on Event (before insert, before update) {
Set<Id>CIds = new Set<Id>();for (Event E:trigger.new)
{String wId = e.WhoId; If(wID!=null && wId.startsWith('003')&& !cIds.contains(e.WhoId))
{cIds.add(e.WhoId);}}
    
    List<Contact> EventC = [Select Id, Fortune_1000_2013_Ranking__c from Contact where
                            Id in :cIds];
    
    Map<Id, Contact> CMap = new Map<Id, Contact>(); for (Contact c: EventC)
        
    {CMap.put(c.Id,c);}
    
    for (Event e:trigger.new)
    {String wId = e.WhoId; if (wId!=null && wId.startswith('003'))
    {Contact thisC = cMap.get(e.WhoId);
    if(thisC!=null)
    {e.Fortune_1000_Ranking__c = thisC.Fortune_1000_2013_Ranking__c;}}}
 
}

---------------------------------------------------------
The test class is throwing an error on the Fortune_1000_2013_Ranking__c line below due to the field is unwritable (value is pulled from the Account record)...any help would be appreciated!!

@isTest
private class UpdateEventFortune1000testclass {
    
static testMethod void UpdateEventFortune1000 () {
List<Contact>Contact = new List<Contact> {new Contact (
    firstname = 'test',
    lastname = 'testtest',
    Fortune_1000_2013_Ranking__c = 1,
    phone = '(555) 555-5555') }; 
    insert Contact;
    
List<Event> e = new List<Event> {new Event(
    WhoID = Contact[0].id, 
    subject = 'test trigger',
    Type = 'Meeting')};
    
    insert e;
    
List<Event> Eventstoupdate = New List<event>{[select id from event where id in :e]};
    for (event eok:eventstoupdate)
    eok.Fortune_1000_Ranking__c=null;
    
    update eventstoupdate;
    
Contact[] c = [select id,Fortune_1000_2013_Ranking__c from Contact where id in :Contact];
    System.assertEquals(1,Contact[0].Fortune_1000_2013_Ranking__c);
    
}
}
Good afternoon community,

I'm trying to populate a lookup field on Opportunity object called Data_Center_Location__c with the Name (or ID) from custom object Data_Center_Location__c, based on picklist field on Opportunity called Location__c.  (so based on picklist selection on Location field on Opportunity, the lookup field will populate with the Name of the corresponding record from the Data_Center_Location__c object....which i'm using as a cross reference table).  Field on the custom object to match with Opportunity.Location__c would be Data_Center_Location__c.Opportunity_Location_Code__c. 

Seems like a simple concept, but i'm not a developer.  So far i've gotten:

trigger UpdateDataCenterLocation on Opportunity (after insert, after update) {
List<String> Opportunity = new List<String>();
    for (Opportunity obj: trigger.new){
        Data_Center_Location__c.add(obj.Data_Center_Location__c.Name);
    }

    list<Data_Center_Location__c> DCLlist = [select Opportunity_Location_Code__c from Data_Center_Location__c where Location__c in :Opportunity];

    if (DCLlist.size() > 0 ){

        for (Integer i = 0; i < Trigger.new.size(); i++)
        {

            if (Trigger.new[i].Data_Center_Location__c != null)  
            {
                Trigger.new[i].Data_Center_Location__c = DCLlist[i].ID;
            }   
            else
            {
                Trigger.new[i].Data_Center_Location__c = null;
            }
        }

    }
}


I don't think this is close to being right.  Does anyone know how to clean this up so it works?...not sure where to begin...
Good morning,

I created a Visualforce email template using "User" object as my recipienttype and "Lead" object as my relatedToType, but when trying to test the window doesn't display the test record field to select but rather states "Visualforce template does not have a controller that can be selected for preview" and gives only the option to send myself a test email without being able to attach a record to use for the test (what's being tested is how the record details is displayed).

Email Template is as follows: 

<messaging:emailTemplate subject="New lead assigned to you: {!relatedto.Name} for Partner Company: <b>{!relatedto.Partner_Company__c}</b>" recipientType="User" relatedToType="Lead">
<messaging:htmlEmailBody >

*** NEW LEAD ASSIGNMENT NOTIFICATION *** <p/>
<br></br>
The following lead has been assigned to you:<p/>
Company:  {!relatedto.Company} <p/>
Lead Name:  {!relatedto.Name} <p/>
<br></br>
<apex:outputLink value="https://na15.salesforce.com/{!relatedto.id}">Click here to view record</apex:outputLink><p/>
<br></br>

</messaging:htmlEmailBody>
</messaging:emailTemplate>

________________________
Seems pretty basic, and i've deployed several other emails before, but this is the first occurance of this message on testing. Does anyone know what may be the culprit?

-d
Good afternoon,

I'm trying to write a test class for a trigger where if there's an open Task on a record (custom object, Sales_Order__c), then the status of the record (Sales Order) = "Pending Question".  When the task is complete, then the status updates to "Ready for Review".  The trigger works fine, but I can't seem to get the test class to save:

@isTest
private class TriggerSalesOrderUpdateonTask {

static testMethod void validateTriggerSalesOrderUpdateonTask () {
List<Sales_Order__c> so = new List<Sales_Order__c> {new Sales_Order__c (
      so.name = '000001')};
        insert so;

List<task> t = new List<task> {new task(
        WhatID = Sales_Order__c[0].id,
        subject = 'test trigger',
        Status = 'Not Started')};
        insert t;

List<task> taskstoupdate = New List<task>{[select id from task where id in :t]};
    for (task tok:taskstoupdate)
    tok.Status = 'Completed';
   
    update taskstoupdate;
   


        system.assertEquals(so.Status__c, 'Sales Order Ready for Review');

    }
}


I'm receiving a Compile Error: Invalid field initializer:so.name at line 6 column 7.  Can someone take a look and see where i'm going wrong, and let me know if you need me to post my trigger on here as well.  Thanks community.
Hello Community, 

Have a simple trigger to update the owner of a custom object (Sales_Order__c) back to the createdby when status is updated to 'Sales Order Completion':


trigger SalesOrderUpdateOwner on Sales_Order__c (before Update)
{
for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' )
  {     
   sc.OwnerId = sc.CreatedById ;
        }
}
}


I just cannot seem to be able to save a test class (i'm also not a developer, so that makes it more challenging to know what i'm doing).  Was trying to create a class where I Insert a new Sales_Order__c record, with the Status__c = 'Sales Order Submitted'.  Then I tried to add an update on the Status__c = 'Sales Order Completion' (which should trigger the code), but nothing takes (various error messages based on how i'm saving it).  Not sure if it's because the status is updated via Javascript button and i have to account for that somehow on the testclass (I get to the testclass where i can create the record, but cannot seem to be able to update the record).  Any assistance is appreciated...
Good morning, 

I have an easy one for someone to answer (easy for a developer, not for me), 

I created a Javascript button to update the Status field on a Custom Object (Sales Order), but only want specific profiles to be able to click this button: the javascript for the button to update works fine, but I'm not sure how to add a line to make it execute only for specific profile(s):

{!requireScript("/soap/ajax/29.0/connection.js")}
var sor = new sforce.SObject("Sales_Order__c");

sor.Id = "{!Sales_Order__c.Id}";

sor.Status__c = "Sales Order Completion";
var result = sforce.connection.update([sor]);
window.location.reload();


Can somebody guide me on how to add a line to allow for only specific profiles (or to restrict certain profiles)
Good Morning,

I'm not a developer but I put together a trigger to update a checkbox field (Trigger_Email_on_Outstanding_Task__c) on the related Lead Object if the corresponding field on a Task (Trigger_email_on_Outstanding_Task__c) is checked (by a workflow):
____________________________________________________________________________________
trigger TriggerTaskNotification on Task (after insert, after update) {


    Set<Id> leadIds=new Set<Id>();

    for(Task t:trigger.new){
        if(t.Trigger_Email_on_Outstanding_Task__c==true){
            if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
              
              if( !leadIds.contains(t.whoid)){   //Dont forget '!'           
                                 leadIds.add(t.whoId);
                      }//if3
               
            }//if 2
        }//if 1
    }//for
   
    /* List<Lead> leadsToUpdate=[SELECT Id, Trigger_Email_on_Outstanding_Task__c FROM Lead WHERE Id IN :leadIds AND Trigger_Email_on_Outstanding_Task__c= True]; */

   Map<Id,Lead>  relatedleads = new Map<Id,Lead>([SELECT Id, Trigger_Email_on_Outstanding_Task__c FROM Lead WHERE Id IN :leadIds]);


   For(Task t2 : trigger.new){
            if(t2.Trigger_Email_on_Outstanding_Task__c==true){

                       if(relatedleads.get(t2.whoid) != null){  //if task is related to lead

                                     //make lead field to 'checked'
                                     relatedleads.get(t2.whoid).Trigger_Email_on_Outstanding_Task__c = true;
                        }//if2

           }//if1

}//for
 
    try{
        update relatedleads.values();
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }
}

______________________________________________________________________________

Looks like i'm receiving a System.NullPointerException: Attempt to de-reference a null object error, on execution of AfterUpdate
from line 8, column 1
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead

I'm assuming that it may be due to a task that doesn't have a related lead record but where the workflow has checked the checkbox on the task.  Is there a line I can omit or add that can account for these instances, where if there's a task with the checkbox checked but with no associated whoid then ignore....i'm assuming my trigger isn't very cleanly written since it's written by me. 

thanks everyone

Good afternoon,

I'm looking to create a button on a custom object that updates the owner and status of the record on the object (Sales_Order__c).  So on button click, the owner changes to a specific queue, and the status updates to "Sales Order Submitted".  What i have below so far:


{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var sor = new sforce.SObject("Sales_Order__c");

sor.Id = '{!Sales_Order__c.Id}';
sor.OwnerId = '00Ge0000000XKF0';
sor.Status__c = "Sales Order Submitted";
var result = sforce.connection.update([sor]);
window.location.reload();

but when i click the button, nothing happens.  Can someone take a look and let me know where i went wrong (no error message, screen just refreshes but changes aren't made).
Good evening, 

my second post today...
so I'm trying to create a trigger that will update the status of a custom object (Sales_Order__c) based on if a related task is open or if task is completed:
Open Task > Update Sales Order Status to "Pending Question"
Completed Task > Update Sales Order Status to "Sales Order Revised"

I'm not close to being a developer, so some of my coding probably has some major flaws:

trigger SalesOrderUpdateonTask on task (after insert, after update ){
set<id> Sales_Order = new set<id>();
for(Task ts : trigger.new)
{
Sales_Order.add(ts.whatid);
Sales_Order =[Select status__c from Sales_Order__c  where id in :Sales_Order];
if(String.valueOf(ts.whatId).startsWith('a1M')==TRUE)
{
Sales_Order__c.Status__c='Pending Question';
update Sales_Order;
}
}
}

On save, get a compile error: illegal assignment from List <Sales_Order__c> to set <id> at line 6...also, have another trigger to Update on task completion:


trigger SalesOrderStatusUpdate on Task (after update)
{
List<ID> Sales_Order = new List<ID>();

for(Task t: Trigger.new)
{
if(t.status == 'Completed')
{
Sales_Order__c.add(t.whatid);
}
}
Map<ID, Sales_Order__c> objMap = new Map<ID, Sales_Order__c>([select id, status__c from Sales_Order__c where id in :Sales_Order__cIDList ]);
List<Sales_Order__c> objList = new List<Sales_Order__c>();
for(Task t: Trigger.new)
{
if(t.Status__c == 'Completed')
{
Sales_Order__c so = objMap.get(t.whatid);
so.status__c = 'Sales Order Revised';
//update remaining fields.
objList.add(so);
}
}
if(objList.size() > 0)
update objList;
}

not sure how to change the variable Sales_Order__c IDlist on line 12 where it will accept, and how to combine the two triggers together into one.  Again, excuse the basic errors since i'm not a developer, but trying to find existing codes that is similar to what i'm looking for.  Thanks once again.


Good afternoon, 

as a non-developer, i'm trying to write a trigger that will update the owner of a custom object record "Sales Order" back to the creator of the record when the status is "Sales Order Completion", 
(pretty basic, which is the only reason I would attempt it myself), code is:


trigger UpdateOwner on Sales_Order__c (after Update)
{  
if((trigger.new[0].Status__c == 'Sales Order Completion') && (trigger.old[0].Status__c != 'Sales Order Completion'))
{       trigger.new[0].OwnerId = trigger.new[0].CreatedById ;
         }
}

it's throwing a Compile Error: line 5:10 no viable alternative at character '' at line 5 column 10
the only thing on line 5 is the }, so i'm assuming i have a missing reference somewhere.  

Any help is appreciated on why i'm getting the error message
Hi community,

I'm not a developer, but was working on a trigger that will update a field on the Lead Object (Trigger_Email_on_Outstanding_Task__c (checkbox) on Lead) when the corresponding field on the related task is updated (Trigger_Email_on_Outstanding_Task__c (checkbox) on Task).  This is due to the limitation of not being able to create cross-object workflows.  So if the custom field is checked on the Task, then it'll update the custom field on the Lead.

Seems simple enough, but again, I'm not a developer so even the simple codes can seem difficult:

What i have is below:

Trigger TriggerTaskNotification on Task (after insert, after update) {


    List<Id> leadIds=new List<Id>();
    for(Task t:trigger.new){
        if(t.Trigger_Email_on_Outstanding_Task__c==true){
            if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
                leadIds.add(t.whoId);
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Trigger_Email_on_Outstanding_Task__c FROM Lead WHERE Id IN :leadIds AND Trigger_Email_on_Outstanding_Task__c= True];
    For (Lead l:leadsToUpdate){
       
    }//for
   
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }
}


Doesn't seem to work, can someone point me to the fix for this, it's all greek to me.

Good morning, 

 

We're implementing Salesforce for Outlook but one gap in functionality is the ability to push an Invitee from an Outlook Calendar Event as the Contact for the Salesforce Event on sync.  What this would involve is someone that can build a macro in Outlook as well as a trigger in Salesforce (or if anyone has a different solution).  If anyone has experience with a similar build, please reply

 

-danny

 

Good afternoon, 

 

I'm trying to create a custom "new" button on a parent record that when clicked it goes to the record type selection page instead of the new child record page.

 

what i have so far is:

 

/a1N/e?retURL=%2F{!Sales_Order__c.Id}&saveURL=%2F{!Sales_Order__c.Id}

 

where Sales Order is the parent record.  So when pressed, it goes to the child record and on Save it goes back to the Parent record, which is what i was needing.  But my child record have multiple record types, so will need to be able to select the record type first.  Does anyone have a way to bring up the record selection page on custom button.

 

thanks everyone

Good afternoon, 

 

we're trying to add a feature for our Outlook integration outside of what's native in Saleforce for Outlook, and was seeing if anyone on this board can recommend anyone that has done work with Outoook.  Specifically what we're needing is a custom field to be added to Outlook Events and a macro that can push the email address of the first invitee on an Event to that new custom field.  

 

If anyone has worked with a Microsoft Partner they can recommend then would appreciate it.  Thanks.

 

-danny

Good morning board,

 

I'm trying to create a New button that on Save / Return you get redirected to the Parent Object after creating a child record.  I saw the code for how to create when there is one Record type for the child record:

 

/003/e?retURL=%2F{!object.Id}&saveURL=%2F{!object.Id}

 

but i have multiple record types where you have the Record Type selection screen before going to the new record screen. 

 

I tried incorporating the entire URL for the Record Type selection screen

 

https://cs15.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01Ie0000000DH9F&retURL=%2Fa1Me0000000hGac&save_new_url=%2Fa1N%2Fe%3FCF00Ne0000000n4do%3D000012%26CF00Ne0000000n4do_lkid%3Da1Me0000000hGac%26retURL%3D%252Fa1Me0000000hGac

 

replacing some of the ID's with {!object.ID} by save_new_url and retURL...as well as by the specific record ID's.  but doesn't seem to allow me to move past the Record Type selection screen.  Has anyone come across this before? (trying to redirect back to parent object on Save but when there are multiple record types for child object)

 

 

 

Hello all, 

I'm trying to write a simple trigger to update new cases created by Process Builder (so assignment rules can re-assign, since these cases hit the rules until it's Edited and Saved manually).  So all the trigger would have to do is re-save the cases (with nothing else to change).  

what i have is: 

trigger caseUpdate on Case (after insert) {
    List<Id> idCase = new List<Id>{};
        for (Case ticket : Trigger.new) 
    update ticket;
  }

But this doesn't seem to work.  Can someone take a look and see where I went wrong?

thanks again community
-danny
Good afternoon, 

I'm working on a simple trigger that can save new cases generated by Process Builder in order for them to hit the assignment rules (Cases created via Process builder will not hit the assignment rules until the Case is Edited and Saved again), and have the following:

trigger caseUpdate on Case (after insert) {
List <Case> newCases = new List <Case>();
    for (Case ticket : Trigger.new) {
        ticket.Status = 'Pending Customer Information';        
    }
    update newCases;
    }

Can someone take a look to see if I missed anything, i'm not a developer so wanted to get a more experience eye on this to validate that it looks okay. 

Thanks community
-danny
Good morning everyone,  

I have a trigger that will assign a lookup value from a custom object (data_center_location__c) to an Opportunity based on a picklist field (location__c) on the Opportunity.  The trigger works okay, but i'm having trouble with my test class.  I'm receiving the Expression error when trying to save.  I also have to state that i'm not a developer so I don't have a great understanding of basic concepts when it comes to test classes:

Trigger is:

trigger UpdateDataCenterLocation on Opportunity (before insert, before update){
      Set<String> locationSet = new Set<String>();
      Map<String,Id> mapLocationSetwithDataCntr = new Map<String,Id>();
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c)){
              locationSet.add(obj.Location__c);
          }
      }
      if(!locationSet.isEmpty()){
          for(Data_Center_Location__c dataCenter : [SELECT Id,Opportunity_Location_Code__c FROM Data_Center_Location__c WHERE Opportunity_Location_Code__c IN :locationSet]){
              mapLocationSetwithDataCntr.put(dataCenter.Opportunity_Location_Code__c,dataCenter.Id);//Expecting there will be one record for each location, otherwise this map will have last Data_Center_Location__c Id
          }
      }
      for (Opportunity obj: trigger.new){
          if(!String.isBlank(obj.Location__c) && mapLocationSetwithDataCntr != null && mapLocationSetwithDataCntr.get(obj.Location__c) != null){
                  obj.Data_Center_Location__c = mapLocationSetwithDataCntr.get(obj.Location__c);
        }
          else{
              obj.Data_Center_Location__c = null;
          }
      }
  }

________
Again, the trigger works as should, the test class on the other hand doesn't:

@isTest

    Private class UpdateDataCenterLocationTestClass {
        static testMethod void UpdateDataCenterLocation () {
    
        List <Opportunity> OpportunityLst = new List <Opportunity>();
        Opportunity Opp = new Opportunity ();
       Opportunity.Name = 'test Opportunity';
       Opportunity.Location__c = 'TX-DAL-03LEW' ;
       Opportunity.Stagename = 'Stage 1: Qualified Prospect';
       
       Opportunity.Closedate = '2015, 2, 26';
        OpportunityLst.add(opp);
        
        insert Opp;
    
    }
    }

--------------------------
For the test class, i'm just trying to create an Opportunity with the location__c field populated with a value, seems easy enough.  Any guidance would be much appreciated.

Thanks everyone
-d
Good afternoon,

I'm having an issue with getting proper coverage on test class (i'm not a developer).  The trigger is to bring down a field value to a custom field on an event (event field 'Fortune_1000_Ranking__c') from the related Contact record on the event.  The field originates from the Account and is a formula field on the Contact record ('Fortune_1000_2013_Ranking__c').  the trigger seems to work fine:

trigger UpdateEventFortune1000 on Event (before insert, before update) {
Set<Id>CIds = new Set<Id>();for (Event E:trigger.new)
{String wId = e.WhoId; If(wID!=null && wId.startsWith('003')&& !cIds.contains(e.WhoId))
{cIds.add(e.WhoId);}}
    
    List<Contact> EventC = [Select Id, Fortune_1000_2013_Ranking__c from Contact where
                            Id in :cIds];
    
    Map<Id, Contact> CMap = new Map<Id, Contact>(); for (Contact c: EventC)
        
    {CMap.put(c.Id,c);}
    
    for (Event e:trigger.new)
    {String wId = e.WhoId; if (wId!=null && wId.startswith('003'))
    {Contact thisC = cMap.get(e.WhoId);
    if(thisC!=null)
    {e.Fortune_1000_Ranking__c = thisC.Fortune_1000_2013_Ranking__c;}}}
 }

Yet i'm having issues with the Test class and getting proper coverage:
@isTest
private class UpdateEventFortune1000testclass {
    
static testMethod void UpdateEventFortune1000 () {
 
   
List<Account>Account = new List<Account> {new Account (
    name = 'test company',
    Fortune_1000_2013_Ranking__c = 1,
    phone = '(555) 555-5555') };
    insert Account;

List<Contact>Contact = new List<Contact> {new Contact (
    firstname = 'test',
    lastname = 'testtest',
    phone = '(555) 555-5555') };    
    insert Contact;
    
List<Event> e = new List<Event> {new Event(
    WhoID = Contact[0].id,
    subject = 'test trigger',
    Type = 'Meeting')};
    
    insert e;
    
List<Event> Eventstoupdate = New List<event>{[select id from event where id in :e]};
    for (event eok:eventstoupdate);
    
    update eventstoupdate;
    
Contact[] c = [select id,Fortune_1000_2013_Ranking__c from Contact where id in :Contact];
    System.assertEquals(1,Contact[0].Fortune_1000_2013_Ranking__c);
    
}
}

Can someone take a look at the test class and see what is wrong with it, i'm not experienced enough on the development side to really see where the error lies.

-d
Good evening, 

need help getting the proper test coverage on trigger, and one issue i'm having with the test class is the field that i'm actually trying to test.  the trigger is to populate an Event record custom field ('Fortune_1000_Ranking__c') from a field pulled from the related Contact ('Fortune_1000_2013_Ranking__c'), which is actually a forrmula field pulled from the same field on the Account record (master-detail).  The trigger works fine:

trigger UpdateEventFortune1000 on Event (before insert, before update) {
Set<Id>CIds = new Set<Id>();for (Event E:trigger.new)
{String wId = e.WhoId; If(wID!=null && wId.startsWith('003')&& !cIds.contains(e.WhoId))
{cIds.add(e.WhoId);}}
    
    List<Contact> EventC = [Select Id, Fortune_1000_2013_Ranking__c from Contact where
                            Id in :cIds];
    
    Map<Id, Contact> CMap = new Map<Id, Contact>(); for (Contact c: EventC)
        
    {CMap.put(c.Id,c);}
    
    for (Event e:trigger.new)
    {String wId = e.WhoId; if (wId!=null && wId.startswith('003'))
    {Contact thisC = cMap.get(e.WhoId);
    if(thisC!=null)
    {e.Fortune_1000_Ranking__c = thisC.Fortune_1000_2013_Ranking__c;}}}
 
}

---------------------------------------------------------
The test class is throwing an error on the Fortune_1000_2013_Ranking__c line below due to the field is unwritable (value is pulled from the Account record)...any help would be appreciated!!

@isTest
private class UpdateEventFortune1000testclass {
    
static testMethod void UpdateEventFortune1000 () {
List<Contact>Contact = new List<Contact> {new Contact (
    firstname = 'test',
    lastname = 'testtest',
    Fortune_1000_2013_Ranking__c = 1,
    phone = '(555) 555-5555') }; 
    insert Contact;
    
List<Event> e = new List<Event> {new Event(
    WhoID = Contact[0].id, 
    subject = 'test trigger',
    Type = 'Meeting')};
    
    insert e;
    
List<Event> Eventstoupdate = New List<event>{[select id from event where id in :e]};
    for (event eok:eventstoupdate)
    eok.Fortune_1000_Ranking__c=null;
    
    update eventstoupdate;
    
Contact[] c = [select id,Fortune_1000_2013_Ranking__c from Contact where id in :Contact];
    System.assertEquals(1,Contact[0].Fortune_1000_2013_Ranking__c);
    
}
}
Good afternoon community,

I'm trying to populate a lookup field on Opportunity object called Data_Center_Location__c with the Name (or ID) from custom object Data_Center_Location__c, based on picklist field on Opportunity called Location__c.  (so based on picklist selection on Location field on Opportunity, the lookup field will populate with the Name of the corresponding record from the Data_Center_Location__c object....which i'm using as a cross reference table).  Field on the custom object to match with Opportunity.Location__c would be Data_Center_Location__c.Opportunity_Location_Code__c. 

Seems like a simple concept, but i'm not a developer.  So far i've gotten:

trigger UpdateDataCenterLocation on Opportunity (after insert, after update) {
List<String> Opportunity = new List<String>();
    for (Opportunity obj: trigger.new){
        Data_Center_Location__c.add(obj.Data_Center_Location__c.Name);
    }

    list<Data_Center_Location__c> DCLlist = [select Opportunity_Location_Code__c from Data_Center_Location__c where Location__c in :Opportunity];

    if (DCLlist.size() > 0 ){

        for (Integer i = 0; i < Trigger.new.size(); i++)
        {

            if (Trigger.new[i].Data_Center_Location__c != null)  
            {
                Trigger.new[i].Data_Center_Location__c = DCLlist[i].ID;
            }   
            else
            {
                Trigger.new[i].Data_Center_Location__c = null;
            }
        }

    }
}


I don't think this is close to being right.  Does anyone know how to clean this up so it works?...not sure where to begin...
Good afternoon,

I'm trying to write a test class for a trigger where if there's an open Task on a record (custom object, Sales_Order__c), then the status of the record (Sales Order) = "Pending Question".  When the task is complete, then the status updates to "Ready for Review".  The trigger works fine, but I can't seem to get the test class to save:

@isTest
private class TriggerSalesOrderUpdateonTask {

static testMethod void validateTriggerSalesOrderUpdateonTask () {
List<Sales_Order__c> so = new List<Sales_Order__c> {new Sales_Order__c (
      so.name = '000001')};
        insert so;

List<task> t = new List<task> {new task(
        WhatID = Sales_Order__c[0].id,
        subject = 'test trigger',
        Status = 'Not Started')};
        insert t;

List<task> taskstoupdate = New List<task>{[select id from task where id in :t]};
    for (task tok:taskstoupdate)
    tok.Status = 'Completed';
   
    update taskstoupdate;
   


        system.assertEquals(so.Status__c, 'Sales Order Ready for Review');

    }
}


I'm receiving a Compile Error: Invalid field initializer:so.name at line 6 column 7.  Can someone take a look and see where i'm going wrong, and let me know if you need me to post my trigger on here as well.  Thanks community.
Hello Community, 

Have a simple trigger to update the owner of a custom object (Sales_Order__c) back to the createdby when status is updated to 'Sales Order Completion':


trigger SalesOrderUpdateOwner on Sales_Order__c (before Update)
{
for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' )
  {     
   sc.OwnerId = sc.CreatedById ;
        }
}
}


I just cannot seem to be able to save a test class (i'm also not a developer, so that makes it more challenging to know what i'm doing).  Was trying to create a class where I Insert a new Sales_Order__c record, with the Status__c = 'Sales Order Submitted'.  Then I tried to add an update on the Status__c = 'Sales Order Completion' (which should trigger the code), but nothing takes (various error messages based on how i'm saving it).  Not sure if it's because the status is updated via Javascript button and i have to account for that somehow on the testclass (I get to the testclass where i can create the record, but cannot seem to be able to update the record).  Any assistance is appreciated...
Good afternoon,

I'm looking to create a button on a custom object that updates the owner and status of the record on the object (Sales_Order__c).  So on button click, the owner changes to a specific queue, and the status updates to "Sales Order Submitted".  What i have below so far:


{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var sor = new sforce.SObject("Sales_Order__c");

sor.Id = '{!Sales_Order__c.Id}';
sor.OwnerId = '00Ge0000000XKF0';
sor.Status__c = "Sales Order Submitted";
var result = sforce.connection.update([sor]);
window.location.reload();

but when i click the button, nothing happens.  Can someone take a look and let me know where i went wrong (no error message, screen just refreshes but changes aren't made).
Good evening, 

my second post today...
so I'm trying to create a trigger that will update the status of a custom object (Sales_Order__c) based on if a related task is open or if task is completed:
Open Task > Update Sales Order Status to "Pending Question"
Completed Task > Update Sales Order Status to "Sales Order Revised"

I'm not close to being a developer, so some of my coding probably has some major flaws:

trigger SalesOrderUpdateonTask on task (after insert, after update ){
set<id> Sales_Order = new set<id>();
for(Task ts : trigger.new)
{
Sales_Order.add(ts.whatid);
Sales_Order =[Select status__c from Sales_Order__c  where id in :Sales_Order];
if(String.valueOf(ts.whatId).startsWith('a1M')==TRUE)
{
Sales_Order__c.Status__c='Pending Question';
update Sales_Order;
}
}
}

On save, get a compile error: illegal assignment from List <Sales_Order__c> to set <id> at line 6...also, have another trigger to Update on task completion:


trigger SalesOrderStatusUpdate on Task (after update)
{
List<ID> Sales_Order = new List<ID>();

for(Task t: Trigger.new)
{
if(t.status == 'Completed')
{
Sales_Order__c.add(t.whatid);
}
}
Map<ID, Sales_Order__c> objMap = new Map<ID, Sales_Order__c>([select id, status__c from Sales_Order__c where id in :Sales_Order__cIDList ]);
List<Sales_Order__c> objList = new List<Sales_Order__c>();
for(Task t: Trigger.new)
{
if(t.Status__c == 'Completed')
{
Sales_Order__c so = objMap.get(t.whatid);
so.status__c = 'Sales Order Revised';
//update remaining fields.
objList.add(so);
}
}
if(objList.size() > 0)
update objList;
}

not sure how to change the variable Sales_Order__c IDlist on line 12 where it will accept, and how to combine the two triggers together into one.  Again, excuse the basic errors since i'm not a developer, but trying to find existing codes that is similar to what i'm looking for.  Thanks once again.


Good afternoon, 

as a non-developer, i'm trying to write a trigger that will update the owner of a custom object record "Sales Order" back to the creator of the record when the status is "Sales Order Completion", 
(pretty basic, which is the only reason I would attempt it myself), code is:


trigger UpdateOwner on Sales_Order__c (after Update)
{  
if((trigger.new[0].Status__c == 'Sales Order Completion') && (trigger.old[0].Status__c != 'Sales Order Completion'))
{       trigger.new[0].OwnerId = trigger.new[0].CreatedById ;
         }
}

it's throwing a Compile Error: line 5:10 no viable alternative at character '' at line 5 column 10
the only thing on line 5 is the }, so i'm assuming i have a missing reference somewhere.  

Any help is appreciated on why i'm getting the error message