• cpo87
  • NEWBIE
  • 0 Points
  • Member since 2005

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 31
    Replies

I have created a custom hyperlink that only works when you aren't in the service console. The hyperlink is on my case page layout.

 

Here is the link -

 

https://na5.salesforce.com/00U/e?aid=02370000001LDFh&anm=Operations+System+Alert+Calendar&evt5={!Cas..."500"&evt3={!Case.CaseNumber}&retURL=%2F00U%2Fc%3FcType%3D1%26cal%3DOperations%2BSystem%2BAlert%2BCalendar%26cal_lkid%3D02370000001LDFh%26cal_lkold%3DOperations%2BSystem%2BAlert%2BCalendar&what_id=" &{!Case.Id} , "Create Event")&isdtp=vw

 

This works perfectly well. It populates the event subject, the related to case, and assigns to a public calendar.

evt5 = subject

evt3_mlktp = related to object

evt3 = case number

 

Does anyone out there know why this would not work when you are in the services console application?  The hyperlink brings up a new event page but doesn't pass any parameters and doesn't associate to the public calendar.  Salesforce support just says that custom links aren't supported by SF.

 

Thanks,

 

Christian

  • July 16, 2013
  • Like
  • 0

Hello all,

 

I would like to populate a custom campaign lookup field on leads using a trigger.  This trigger should look at each new Campaign Member created, check to see if this field on the associated Lead is null and if so populate the campaign ID from the Campaign Member record.  

 

I've created the below code but i can't figure out what I'm doing wrong.  My current error is saying I  have an unexpected token '{' after my last IF statement.

 

I haven't gotten to the check if the field is Null yet.

 

trigger trgCM_PopulatePrimaryCampaign on CampaignMember (before insert) {
//create and populate a list of Campaign Member Lead IDs	
    List<ID> cmLeadID = new List<ID>();
    for(CampaignMember cm:Trigger.new){
        cmLeadID.add(cm.LeadID);
    }
//create a list of leads that have Lead Ids in cmLeadID List<Lead> leads = [ SELECT Id, Primary_Campaign_Source_Lead__c FROM Lead WHERE ID IN :cmLeadID ];
//create and populate a set of lead IDs using the leads list Set<ID> leadIDs = new Set<ID>(); for(Lead lead:leads){ leadIDs.add(lead.ID); } //check to see if Primary_Campaign_Source_Lead__c is null and if so populate with the cm.CampaignID
for(CampaignMember cm:Trigger.new){ if(leadIDs.contains(cm.LeadID){ lead.Primary_Campaign_Source_Lead__c = cm.CampaignID; } } }

 Can anyone steer me in the right direction?

 

Thanks!

 

Christian

  • July 11, 2013
  • Like
  • 0

I have created a custom hyperlink that only works when you aren't in the service console.  The hyperlink is on my case page layout.  

 

Here is the link - 

 

https://na5.salesforce.com/00U/e?aid=02370000001LDFh&anm=Operations+System+Alert+Calendar&evt5={!Case.Account}&evt3_mlktp="500"&evt3={!Case.CaseNumber}&retURL=%2F00U%2Fc%3FcType%3D1%26cal%3DOperations%2BSystem%2BAlert%2BCalendar%26cal_lkid%3D02370000001LDFh%26cal_lkold%3DOperations%2BSystem%2BAlert%2BCalendar&what_id=" &{!Case.Id} , "Create Event")&isdtp=vw

 

This works perfectly well.  It populates the event subject, the related to case, and assigns to a public calendar.  

 

evt5 = subject

evt3_mlktp = related to object

evt3 = case number

 

Does anyone out there know why this would not work when you are in the services console application?  The hyperlink brings up a new event page but doesn't pass any parameters and doesn't associate to the public calendar.

 

Thanks,

 

Christian

  • May 02, 2013
  • Like
  • 0

I'm trying to provide a VF page inside a custom object page layout.  I would like to allow my users to edit their information and click the save button without the VF page changing it's position within the inner frame.  (See Screen shots)

 

 

Custom Object with VF Page before clicking Save commandButton

 

RPI Object Before VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Custom Object with VF Page after clicking the Save commandButton

 

RPI Object After VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What is the best way to correct this?  Is it possible to have the parent page refresh after the save commandButton is clicked.

 

Here is my code....

 

<apex:page StandardController="RPI_Request__c">
  <apex:form >
    <apex:pageBlock >
      <apex:panelGrid dir="LTR" columns="6" id="theGrid">
          <apex:outputText value="" id="one"/>
          <apex:outputText value="Owner(s)" id="two"/>
          <apex:outputText value="Start" id="three"/>
          <apex:outputText value="Finish" id="four"/>
          <apex:outputText value="Fix Needed?" id="five"/>
          <apex:outputText value="Estimated Completion" id="six"/>
          <apex:outputText value="Gather/Create Specifications: " id="seven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Owner_Lookup__c}" id="eight"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Start__c}" id="nine"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Finish__c}" id="ten"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Fix__c}" id="eleven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Est_Comp__c}" id="twelve"/>
          <apex:outputText value="Review/Finalize Specifications: " id="thirteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Owner_Lookup__c}" id="fourteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Start__c}" id="fifteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Finish__c}" id="sixteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Fix__c}" id="seventeen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Est_Comp__c}" id="eighteen"/>
          <apex:outputText value="Create Matrix: " id="nineteen"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Owner_Lookup__c}" id="twenty"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Start__c}" id="twentyone"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Finish__c}" id="twentytwo"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Fix__c}" id="twentythree"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Est_Comp__c}" id="twentyfour"/>
          <apex:outputText value="Finalize Matrix: " id="twentyfive"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Owner_Lookup__c}" id="twentysix"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Start__c}" id="twentyseven"/> 
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Finish__c}" id="twentyeight"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Fix__c}" id="twentynine"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Est_Comp__c}" id="thirty"/>           
          <apex:outputText value="Mapping/Development: " id="thirtyone"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Owner_Lookup__c}" id="thirtytwo"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Start__c}" id="thirtythree"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Finish__c}" id="thirtyfour"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Fix__c}" id="thirtyfive"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Est_Comp__c}" id="thirtysix"/>
          <apex:outputText value="QA: " id="thirtyseven"/>
              <apex:inputField value="{!RPI_Request__c.QA_Owner_Lookup__c}" id="thirtyeight"/>
              <apex:inputField value="{!RPI_Request__c.QA_Start__c}" id="thirtynine"/>
              <apex:inputField value="{!RPI_Request__c.QA_Finish__c}" id="forty"/>
              <apex:inputField value="{!RPI_Request__c.QA_Fix__c}" id="fortyone"/>
              <apex:inputField value="{!RPI_Request__c.QA_Est_Comp__c}" id="fortytwo"/>   
          <apex:outputText value="Integrated Testing: " id="fortythree"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Owner_Lookup__c}" id="fortyfour"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Start__c}" id="fortyfive"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Finish__c}" id="fortysix"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Fix__c}" id="fortyseven"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Est_Comp__c}" id="fortyeight"/>     
        </apex:panelGrid>
     </apex:pageBlock>  
     <apex:commandButton action="{!save}" value="Save" alt="Save" id="saveButton"/>
  </apex:form>
</apex:page>

 

  • March 15, 2011
  • Like
  • 1

Hello All,

 

I'm receiving a 'Duplicate id in list' error.  I am trying to total the number of projects associated to an opportunity.  The join between these two is a lookup field on projects.

 

I am receiving this error...

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgOpp_FIProjectOnlyCount: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 006S0000004dleLIAQ Trigger.trgOpp_FIProjectOnlyCount: line 21, column 5: []

 

Trigger

 

trigger trgOpp_FIProjectOnlyCount on SFDC_Project__c (after insert, after update) {
 //Find ID for 'File Integration Project - Document' and 'File Integration Project - Master' Record Type 
    Id RecType = [Select r.Id from RecordType r WHERE r.Name = 'File Integration Project - Document' AND r.SobjectType = 'SFDC_Project__c' Limit 1].Id;
	Id RecType2 = [Select r.Id from RecordType r WHERE r.Name = 'File Integration Project - Master' AND r.SobjectType = 'SFDC_Project__c' Limit 1].Id;
	
    List<Opportunity> opptys = new List<Opportunity>();
    integer pct;
    for(SFDC_Project__c p : trigger.new){
        if(p.RecordTypeId == RecType || p.RecordTypeId == RecType2){
            pct = [Select Count() FROM SFDC_Project__c p 
                                WHERE p.Opportunity__c = :p.Opportunity__c
                                AND p.Project_State__c != 'Completed'
                           ];

       Opportunity oid = [Select Count_of_FI_Projects__c from Opportunity WHERE id =:p.Opportunity__c ];
            oid.Count_of_FI_Projects__c = pct;
          
       opptys.add(oid);
       }
    }
    system.debug('\n' + opptys + '\n');
    Database.update(opptys);
}

 

 

UnitTest

 

@isTest
private class testOpp_FIProjectOnlyCount {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
 
        Id RecType = [Select r.Id from RecordType r WHERE r.Name = 'File Integration Project - Document' AND r.SobjectType = 'SFDC_Project__c' Limit 1].Id;
		Id RecType2 = [Select r.Id from RecordType r WHERE r.Name = 'File Integration Project - Master' AND r.SobjectType = 'SFDC_Project__c' Limit 1].Id;     	
		List<SFDC_Project__c> projList = new List<SFDC_Project__c>();
		
        Account a = new Account();
        	a.Name = 'Test Vendor Account';
        	a.Type = 'Vendor';
        	a.Industry = 'Unknown';
        	a.ERP_Acct_App__c = 'Unknown';
        	Database.insert(a);
        	System.debug(a.ID);
			Account acct = [Select ID From Account a Limit 1];  
        	ID aid = acct.Id;
        Account b = new Account();
        	b.Name = 'Test Retailer Account';
        	b.Type = 'Buyer';
        	b.Industry = 'Unknown';
        	b.ERP_Acct_App__c = 'Unknown';
			Database.insert(b);
			Account acct2 = [Select ID From Account b Limit 1];
        	ID bid = acct2.Id;
        Campaign c = new Campaign();
        	c.Name = 'Test Campaign';
        	c.IsActive = True;
        	Database.insert(c);
        	Campaign cam = [Select ID From Campaign c Limit 1];
        	ID cid = cam.ID;
        Contact con = new Contact();
        	con.LastName = 'Test Last Name';
        	con.AccountId = aid;
        	Database.insert(con);
        	Contact cont = [Select ID From Contact con Limit 1];
        	ID conid = cont.ID;
        Opportunity mo = new Opportunity();
        	mo.CampaignId = cid;
        	mo.Name = 'Test Master Opportunity';
        	mo.LeadSource = 'Other';
        	mo.StageName = 'Suspect - 0%';
        	mo.CloseDate = system.today();
        	mo.AccountId = aid;
        	Database.insert(mo);
        	Opportunity o = [Select ID From Opportunity mo Limit 1];
        	ID moid = o.ID;       	
        SFDC_Project__c mproj = new SFDC_Project__c();
        	mproj.Name = 'Test Master Project';
        	mproj.Project_Type__c = 'File Integration';
        	mproj.SFDC_Project_Status__c = 'Not Started';
        	mproj.RecordTypeId = RecType2;
        	mproj.Account__c = aid;
        	mproj.Related_to_Account_c__c = bid;
        	mproj.Contact__c = conid;
        	mproj.Opportunity__c = moid;
        	Database.insert(mproj);
        	SFDC_Project__c proj = [Select ID From SFDC_Project__c mproj Limit 1];
        	ID mprojid = proj.ID;  	

        for(Integer i=0; i<21; i++){
        	SFDC_Project__c p = new SFDC_Project__c();
        		p.Name = 'Test Doc Project ' + i;
        		p.Parent_Implementation_Project__c = mprojid;
        		p.Project_Type__c = 'File Integration';
        		p.SFDC_Project_Status__c = 'Not Started';
        		p.RecordTypeId = RecType;
        		p.Account__c = aid;
        		p.Related_to_Account_c__c = bid;
        		p.Contact__c = conid;
        		p.Opportunity__c = moid;
        		projList.add(p);
        }
        Database.insert(projList);
        System.assert(mo.Count_of_FI_Projects__c == 22); 
    }
}

 

 

Any suggestions?

 

Thanks,

 

Christian

 

 

  • February 24, 2011
  • Like
  • 0

Last Conversation Date - (Date field)

Days Since Last Conversation Date - (Formula field) = Now() - Last Conversation Date

Account Status - (Picklist field)

 

Here is what I'm trying to do.  I have a field on accounts that shows the date of a last conversation.  I have another field that calculates how many days it's been since that last conversation.  When this field hits 121 days I want to update a picklist field on the account to say "Needs Contact".  The Days Since Last Conversation Date formula is being updated by the system time updating, not an active UI edit.  Because of this I can't use a WorkFlow to update the Account Status.  When I've tried the WorkFlow doesn't fire because it isn't recognizing that an update took place.  I have also tried to create a trigger to make this work to no avail.  Here is my trigger.

 

 

trigger ProtectedStatusUpdate on Account (before update) {

    Account acct = Trigger.new[0];
     
//check to see if the Days Since Last Meaningful Conversation Date is greater than 120
    if(acct.Days_Since_Last_Activity_Modified_Date__c == 121){
      if(acct.Account_Rank__c == 'Sales Hot' || acct.Account_Rank__c == 'Sales Warm' || acct.Account_Rank__c == 'Sales Cool'){
      acct.Account_Rank__c = 'Needs Contact';
      }
     }
}

 Any suggestions would be greatly appreciated.

 

Thanks,

 

Christian

 

  • July 21, 2010
  • Like
  • 0

I have a trigger that works when I limit the Count query to only 1 where statement.  I am trying to figure out how to make it work with multiple criteria.

 

Code that works...

 

Integer accounts = [SELECT COUNT()FROM Account WHERE (Account.ownerId =: userInfo.getUserId())];

Code that doesn't work...

 

Integer accounts = [SELECT COUNT()FROM Account WHERE (Account.ownerId =: userInfo.getUserId()) AND (Account_Status__c NOT IN ('Current Customer', 'Seasonal - On', 'Seasonal - Off')) AND (Enb_Churn_Exclusion__c != null)];

Any ideas?

 

Thanks,

 

Christian

 

 

  • May 26, 2010
  • Like
  • 0

I am trying to create a new lead and task when a custom object called TPI_Supplier_Tracker__c is entered into the database.  I am getting null value errors and I think this is because the data hasn't been committed to the DB yet.  Here is the error I'm getting...

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger TPIEventCreateLeadTask caused an unexpected exception, contact your administrator: TPIEventCreateLeadTask: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]: Trigger.TPIEventCreateLeadTask: line 23, column 13

 

Here is my code...

 

 

trigger TPIEventCreateLeadTask on TPI_Supplier_Tracker__c (before insert) {

//On entry of a new TPI_Supplier_Tracker__c record create a lead, associate it to a campaign, and assign a task
//TPI_Supplier_Tracker__c records will be created in mass once a week

List<TPI_Supplier_Tracker__c> tpiList = new List<TPI_Supplier_Tracker__c>();

for(TPI_Supplier_Tracker__c tpi :Trigger.new){
tpiList.add(tpi);

Lead lead = new Lead(
LastName = '[Unknown]',
Company = tpi.Account__r.Name,
OwnerId = tpi.Account__r.OwnerId,
Status = 'Open',
LeadSource = 'Other',
ERP_Accounting_System__c = 'Unknown',
Existing_EDI_Application__c = 'Unknown',
Potential_Trading_Partners__c = tpi.Related_to_Account__r.Name);
// tpi.addError('Error - ' + tpi);
insert lead;
}
}

 

If I uncomment the addError it shows that there is data...

 

Error - TPI_Supplier_Tracker__c:{Account__c=0016000000NpaBiAAJ, IsDeleted=false, Last_Product_Activity__c=2010-03-15 00:00:00, Related_to_Account__c=0016000000NpaBhAAJ, Data_Being_Put_Into_TPI__c=true}

 

I want to assign the Lead.Name and Lead.OwnerId using information from the account related to the TPI_Supplier_Tracker__c record.  Is this possible and how can I access that information when the system is saying that they are blank?

 

Thanks,

 

Christian

 

 

  • March 15, 2010
  • Like
  • 0

I have a trigger that I created on Email Message that populates a date in the parent case of the most recent email message created date.  This allows me to run a workflow that reopens a case if an email comes in after the case has closed.  Here is the code for the trigger.

 

 

trigger LastEmailDateTime on EmailMessage (after insert) { EmailMessage email = Trigger.new[0]; //Populate the case with the Last EmailMessage CreatedDate value for(EmailMessage em:[Select CreatedDate, ParentID from EmailMessage where Id = :email.Id limit 1]){ for(Case c:[Select Id, Last_Email_Date_Time__c from Case where Id = :em.ParentId limit 1]){ c.Last_Email_Date_Time__c = em.CreatedDate; update c; } } }

 

 I recently installed the Case Age in Business Hours app.  Since I did that I am getting script exception errors for too many SOQL queries.  Here is an example of the error I receive.

 

 Developer script exception : LastEmailDateTime : LastEmailDateTime: execution of AfterInsert  caused by: System.Exception: Too many SOQL queries: 22  Trigger.LastEmailDateTime: line 7, column 23

 

Any suggestions on how I can reduce the number of SOQL queries?

 

Thanks!

 

  • March 01, 2010
  • Like
  • 0

I am trying to determine the best way to limit the number of accounts a given user owns.  In my case it is accounts with and attribute of "Protected".  I would like them to get an error when they go above 100 protected accounts.  I figured the best way to do this was by writing a trigger that queries the db and if the count() query is greater than 100 throw the error.

 

Is that the right way to do this?  It is beginning to look like I can't throw an error with apex, do I need to use apex and visualforce to acheive this?  Here is my apex so far.

 

 

trigger AccountTop100Trigger on Account (before insert, before update) { Account accs = Trigger.new[0]; If(accs.Protected__c == true){ Integer accounts = [SELECT COUNT()FROM Account WHERE Account.ownerId =: userInfo.getUserId()]; system.debug(accounts); //Output an error if the owner goes over 100 accounts If(accounts > 100){ system.debug('You are over your limit of 100 protected accounts, this account cannot be marked as protected until your remove another protected account.'); } } }

 

Thanks!

  • February 18, 2010
  • Like
  • 0

I have created a field on account that behaves like the Last Activity field except the task doesn't have to be marked with a status of Completed and the date populated on the account is the tasks Last Modified Date. The point of this field is to show the most recent time a task was worked on a given account. My code also takes into consideration tasks associated to an opportunity or a contact and roles it up to the account.

 

The issue I'm having is that the task and test code execute properly in my Sandbox, coverage of 100%, but when I execute it in Eclipse my system.assert code fails because it is saying that the acct.Last_Activity_Modified_Date__c is not equal to the task's last modified date. For some reason in Eclipse the acct.Last_Activity_Modified_Date__c is Null.

 

Why would the code work in sandbox but not Eclipse?

 

Please help! See trigger, unit tests, and debug log below.

 

trigger UpdateLastActivityDate on Task (after insert, after update) { Task task = Trigger.new[0]; Account acct = new Account(); //Determine if the task WhatId (Related To) field is populated if(task.WhatId!=null){ //Get the first 3 digits of the WhatId to determine which object it is referring to String tPrefix = task.WhatId; tPrefix = tPrefix.subString(0,3); //If the object is an account then update the account Last_Activity_Modified_Date to the task Last_Modified_Date if(tPrefix == '001'){ for(Account a:[Select Id, Last_Activity_Modified_Date__c from Account where Id = :task.whatId limit 1]){ acct = a; Datetime t = task.LastModifiedDate; Date d = Date.newInstance(t.year(),t.month(),t.day()); if(d > acct.Last_Activity_Modified_Date__c || acct.Last_Activity_Modified_Date__c == null) acct.Last_Activity_Modified_Date__c = d; update acct; } } //If the object is an opportunity then get the account id and then update the account Last_Activity_Modified_Date to the task Last_Modified_Date if(tPrefix == '006'){ for(Opportunity o:[Select AccountId from Opportunity]){ for(Account a:[Select Id, Last_Activity_Modified_Date__c from Account where Id = :o.AccountId limit 1]){ acct = a; Datetime t = task.LastModifiedDate; Date d = Date.newInstance(t.year(),t.month(),t.day()); if(d > acct.Last_Activity_Modified_Date__c || acct.Last_Activity_Modified_Date__c == null) acct.Last_Activity_Modified_Date__c = d; update acct; } } } } //Determine if the WhatId is not populated but the WhoID(Name) is (lead or Contact) if(task.WhatId==null && task.WhoId!=null){ //Get the first 3 digits of the WhoId to determine which object it is referring to String tPrefix2 = task.WhoId; tPrefix2 = tPrefix2.subString(0,3); //If the object is a contact then get the account id and then update the account Last_Activity_Modified_Date to the task Last_Modified_Date if(tPrefix2 == '003'){ for(contact c:[Select AccountId from Contact where Id = :task.WhoId]){ for(Account a:[Select Id, Last_Activity_Modified_Date__c from Account where Id = :c.AccountId limit 1]){ acct = a; Datetime t = task.LastModifiedDate; Date d = Date.newInstance(t.year(),t.month(),t.day()); if(d > acct.Last_Activity_Modified_Date__c || acct.Last_Activity_Modified_Date__c == null) acct.Last_Activity_Modified_Date__c = d; update acct; } } } } }

 

@isTest private class TESTLastActivityModifiedDate { static testMethod void testUpdateLastActivityDate(){ Account[] acct = new Account[]{ new Account(Name = 'Test cpoAccount0',Type = 'Vendor',Industry = 'Other',ERP_Acct_App__c = 'Other'), new Account(Name = 'Test cpoAccount1',Type = 'Vendor',Industry = 'Other',ERP_Acct_App__c = 'Other'), new Account(Name = 'Test cpoAccount2',Type = 'Vendor',Industry = 'Other',ERP_Acct_App__c = 'Other') }; insert acct; Date cd = Date.newInstance(2010,02,02); Opportunity oppty = new Opportunity(Name = 'Test cpoOppty', StageName = 'Suspect - 0%', CloseDate = cd, AccountId = acct[1].Id); insert oppty; Contact cont = new Contact(LastName = 'Test cpoContact', AccountId = acct[2].Id); insert cont; Task[] task = new Task[]{ new Task(Subject = 'cpoTest0', whatId = acct[0].Id), new Task(Subject = 'cpoTest1', whatId = oppty.Id), new Task(Subject = 'cpoTest2', whoId = cont.Id) }; Test.startTest(); insert task[0]; insert task[1]; insert task[2]; Test.stopTest(); task[0] = [SELECT ID, LastModifiedDate FROM Task WHERE Subject = 'cpoTest0']; Datetime t0 = task[0].LastModifiedDate; Date d0 = Date.newInstance(t0.year(),t0.month(),t0.day()); acct[0] = [SELECT ID, Last_Activity_Modified_Date__c FROM Account WHERE Name = 'Test cpoAccount0']; system.debug(d0); system.debug(acct[0].Last_Activity_Modified_Date__c); system.assert(acct[0].Last_Activity_Modified_Date__c == d0); task[1] = [SELECT ID, LastModifiedDate FROM Task WHERE Subject = 'cpoTest1']; Datetime t1 = task[1].LastModifiedDate; Date d1 = Date.newInstance(t1.year(),t1.month(),t1.day()); acct[1] = [SELECT ID, Last_Activity_Modified_Date__c FROM Account WHERE Name = 'Test cpoAccount1']; system.assert(acct[1].Last_Activity_Modified_Date__c == d1); task[2] = [SELECT ID, LastModifiedDate FROM Task WHERE Subject = 'cpoTest2']; Datetime t2 = task[2].LastModifiedDate; Date d2 = Date.newInstance(t2.year(),t2.month(),t2.day()); acct[2] = [SELECT ID, Last_Activity_Modified_Date__c FROM Account WHERE Name = 'Test cpoAccount2']; system.assert(acct[2].Last_Activity_Modified_Date__c == d2); } }

Debug Log:

*** Beginning Test 1: TESTLastActivityModifiedDate.static testMethod void testUpdateLastActivityDate()

20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 10, column 5: Insert: LIST:SOBJECT:Account
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 14, column 5: Insert: SOBJECT:Opportunity
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 17, column 5: Insert: SOBJECT:Contact
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 26, column 5: Insert: SOBJECT:Task
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 27, column 5: Insert: SOBJECT:Task
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 28, column 5: Insert: SOBJECT:Task
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 28, column 5:     DML Operation executed in 86 ms
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 31, column 15: SOQL query with 1 row finished in 767 ms
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 36, column 15: SOQL query with 1 row finished in 20 ms
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 38, column 5: 2010-01-15 00:00:00
20100115212535.035:Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 39, column 5: null
System.Exception: Assertion Failed

Class.TESTLastActivityModifiedDate.testUpdateLastActivityDate: line 41, column 5
External entry point

 

  • January 18, 2010
  • Like
  • 0
I am trying to add contact information such as title, phone, and email to tasks.  I have tried to do this through a VisualForce page and I am meeting limited results.  The code below works up to a point.
 
Code:
<apex:page standardController="Task">
  <apex:pageblock title="Contact Details">
    <apex:pageBlockTable value="{!task.who}" var="tc">
      <apex:column headerValue="Task Contact Name" value="{!tc.name}"/>
      <apex:column headerValue="Task Contact ID" value="{!tc.id}"/>
    </apex:pageBlockTable>    
  </apex:pageblock>
</apex:page>

 
I don't seem to be able to access the email, phone, and title fields.  I have reviewed my Enterprise WSDL and I am unsure where I am pulling the information from for the name and id fields because if they were on the contact record then I should be able to pull other contact fields.
 
Any help is appreciated.
  • July 16, 2008
  • Like
  • 0
I am new to S-Controls and Apex and am looking for a nudge in the correct direction regarding solving a problem.
 
Problem: I would like to copy the Partner Name and Partner Role from an opportunity when the opportunity is marked as Closed - Won and then populate those values into a custom object that is also associated to that same opportunity.  The reason for doing this is that I want a status field associated to that partner connection so I would also have a status field in that custom object.
 
Please direct me toward the correct techology to solve this problem.  Thanks!
  • April 25, 2008
  • Like
  • 0

I'm trying to provide a VF page inside a custom object page layout.  I would like to allow my users to edit their information and click the save button without the VF page changing it's position within the inner frame.  (See Screen shots)

 

 

Custom Object with VF Page before clicking Save commandButton

 

RPI Object Before VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Custom Object with VF Page after clicking the Save commandButton

 

RPI Object After VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What is the best way to correct this?  Is it possible to have the parent page refresh after the save commandButton is clicked.

 

Here is my code....

 

<apex:page StandardController="RPI_Request__c">
  <apex:form >
    <apex:pageBlock >
      <apex:panelGrid dir="LTR" columns="6" id="theGrid">
          <apex:outputText value="" id="one"/>
          <apex:outputText value="Owner(s)" id="two"/>
          <apex:outputText value="Start" id="three"/>
          <apex:outputText value="Finish" id="four"/>
          <apex:outputText value="Fix Needed?" id="five"/>
          <apex:outputText value="Estimated Completion" id="six"/>
          <apex:outputText value="Gather/Create Specifications: " id="seven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Owner_Lookup__c}" id="eight"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Start__c}" id="nine"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Finish__c}" id="ten"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Fix__c}" id="eleven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Est_Comp__c}" id="twelve"/>
          <apex:outputText value="Review/Finalize Specifications: " id="thirteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Owner_Lookup__c}" id="fourteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Start__c}" id="fifteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Finish__c}" id="sixteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Fix__c}" id="seventeen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Est_Comp__c}" id="eighteen"/>
          <apex:outputText value="Create Matrix: " id="nineteen"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Owner_Lookup__c}" id="twenty"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Start__c}" id="twentyone"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Finish__c}" id="twentytwo"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Fix__c}" id="twentythree"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Est_Comp__c}" id="twentyfour"/>
          <apex:outputText value="Finalize Matrix: " id="twentyfive"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Owner_Lookup__c}" id="twentysix"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Start__c}" id="twentyseven"/> 
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Finish__c}" id="twentyeight"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Fix__c}" id="twentynine"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Est_Comp__c}" id="thirty"/>           
          <apex:outputText value="Mapping/Development: " id="thirtyone"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Owner_Lookup__c}" id="thirtytwo"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Start__c}" id="thirtythree"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Finish__c}" id="thirtyfour"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Fix__c}" id="thirtyfive"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Est_Comp__c}" id="thirtysix"/>
          <apex:outputText value="QA: " id="thirtyseven"/>
              <apex:inputField value="{!RPI_Request__c.QA_Owner_Lookup__c}" id="thirtyeight"/>
              <apex:inputField value="{!RPI_Request__c.QA_Start__c}" id="thirtynine"/>
              <apex:inputField value="{!RPI_Request__c.QA_Finish__c}" id="forty"/>
              <apex:inputField value="{!RPI_Request__c.QA_Fix__c}" id="fortyone"/>
              <apex:inputField value="{!RPI_Request__c.QA_Est_Comp__c}" id="fortytwo"/>   
          <apex:outputText value="Integrated Testing: " id="fortythree"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Owner_Lookup__c}" id="fortyfour"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Start__c}" id="fortyfive"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Finish__c}" id="fortysix"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Fix__c}" id="fortyseven"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Est_Comp__c}" id="fortyeight"/>     
        </apex:panelGrid>
     </apex:pageBlock>  
     <apex:commandButton action="{!save}" value="Save" alt="Save" id="saveButton"/>
  </apex:form>
</apex:page>

 

  • March 15, 2011
  • Like
  • 1

Hello all,

 

I would like to populate a custom campaign lookup field on leads using a trigger.  This trigger should look at each new Campaign Member created, check to see if this field on the associated Lead is null and if so populate the campaign ID from the Campaign Member record.  

 

I've created the below code but i can't figure out what I'm doing wrong.  My current error is saying I  have an unexpected token '{' after my last IF statement.

 

I haven't gotten to the check if the field is Null yet.

 

trigger trgCM_PopulatePrimaryCampaign on CampaignMember (before insert) {
//create and populate a list of Campaign Member Lead IDs	
    List<ID> cmLeadID = new List<ID>();
    for(CampaignMember cm:Trigger.new){
        cmLeadID.add(cm.LeadID);
    }
//create a list of leads that have Lead Ids in cmLeadID List<Lead> leads = [ SELECT Id, Primary_Campaign_Source_Lead__c FROM Lead WHERE ID IN :cmLeadID ];
//create and populate a set of lead IDs using the leads list Set<ID> leadIDs = new Set<ID>(); for(Lead lead:leads){ leadIDs.add(lead.ID); } //check to see if Primary_Campaign_Source_Lead__c is null and if so populate with the cm.CampaignID
for(CampaignMember cm:Trigger.new){ if(leadIDs.contains(cm.LeadID){ lead.Primary_Campaign_Source_Lead__c = cm.CampaignID; } } }

 Can anyone steer me in the right direction?

 

Thanks!

 

Christian

  • July 11, 2013
  • Like
  • 0

I'm trying to provide a VF page inside a custom object page layout.  I would like to allow my users to edit their information and click the save button without the VF page changing it's position within the inner frame.  (See Screen shots)

 

 

Custom Object with VF Page before clicking Save commandButton

 

RPI Object Before VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Custom Object with VF Page after clicking the Save commandButton

 

RPI Object After VF Page Save

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What is the best way to correct this?  Is it possible to have the parent page refresh after the save commandButton is clicked.

 

Here is my code....

 

<apex:page StandardController="RPI_Request__c">
  <apex:form >
    <apex:pageBlock >
      <apex:panelGrid dir="LTR" columns="6" id="theGrid">
          <apex:outputText value="" id="one"/>
          <apex:outputText value="Owner(s)" id="two"/>
          <apex:outputText value="Start" id="three"/>
          <apex:outputText value="Finish" id="four"/>
          <apex:outputText value="Fix Needed?" id="five"/>
          <apex:outputText value="Estimated Completion" id="six"/>
          <apex:outputText value="Gather/Create Specifications: " id="seven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Owner_Lookup__c}" id="eight"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Start__c}" id="nine"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Finish__c}" id="ten"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Fix__c}" id="eleven"/>
              <apex:inputField value="{!RPI_Request__c.Gather_Create_Specs_Est_Comp__c}" id="twelve"/>
          <apex:outputText value="Review/Finalize Specifications: " id="thirteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Owner_Lookup__c}" id="fourteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Start__c}" id="fifteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Finish__c}" id="sixteen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Fix__c}" id="seventeen"/>
              <apex:inputField value="{!RPI_Request__c.Review_Final_Specs_Est_Comp__c}" id="eighteen"/>
          <apex:outputText value="Create Matrix: " id="nineteen"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Owner_Lookup__c}" id="twenty"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Start__c}" id="twentyone"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Finish__c}" id="twentytwo"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Fix__c}" id="twentythree"/>
              <apex:inputField value="{!RPI_Request__c.Create_Matrix_Est_Comp__c}" id="twentyfour"/>
          <apex:outputText value="Finalize Matrix: " id="twentyfive"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Owner_Lookup__c}" id="twentysix"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Start__c}" id="twentyseven"/> 
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Finish__c}" id="twentyeight"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Fix__c}" id="twentynine"/>
              <apex:inputField value="{!RPI_Request__c.Finalize_Matrix_Est_Comp__c}" id="thirty"/>           
          <apex:outputText value="Mapping/Development: " id="thirtyone"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Owner_Lookup__c}" id="thirtytwo"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Start__c}" id="thirtythree"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Finish__c}" id="thirtyfour"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Fix__c}" id="thirtyfive"/>
              <apex:inputField value="{!RPI_Request__c.Mapping_Dev_Est_Comp__c}" id="thirtysix"/>
          <apex:outputText value="QA: " id="thirtyseven"/>
              <apex:inputField value="{!RPI_Request__c.QA_Owner_Lookup__c}" id="thirtyeight"/>
              <apex:inputField value="{!RPI_Request__c.QA_Start__c}" id="thirtynine"/>
              <apex:inputField value="{!RPI_Request__c.QA_Finish__c}" id="forty"/>
              <apex:inputField value="{!RPI_Request__c.QA_Fix__c}" id="fortyone"/>
              <apex:inputField value="{!RPI_Request__c.QA_Est_Comp__c}" id="fortytwo"/>   
          <apex:outputText value="Integrated Testing: " id="fortythree"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Owner_Lookup__c}" id="fortyfour"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Start__c}" id="fortyfive"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Finish__c}" id="fortysix"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Fix__c}" id="fortyseven"/>
              <apex:inputField value="{!RPI_Request__c.Integrated_Testing_Est_Comp__c}" id="fortyeight"/>     
        </apex:panelGrid>
     </apex:pageBlock>  
     <apex:commandButton action="{!save}" value="Save" alt="Save" id="saveButton"/>
  </apex:form>
</apex:page>

 

  • March 15, 2011
  • Like
  • 1

Last Conversation Date - (Date field)

Days Since Last Conversation Date - (Formula field) = Now() - Last Conversation Date

Account Status - (Picklist field)

 

Here is what I'm trying to do.  I have a field on accounts that shows the date of a last conversation.  I have another field that calculates how many days it's been since that last conversation.  When this field hits 121 days I want to update a picklist field on the account to say "Needs Contact".  The Days Since Last Conversation Date formula is being updated by the system time updating, not an active UI edit.  Because of this I can't use a WorkFlow to update the Account Status.  When I've tried the WorkFlow doesn't fire because it isn't recognizing that an update took place.  I have also tried to create a trigger to make this work to no avail.  Here is my trigger.

 

 

trigger ProtectedStatusUpdate on Account (before update) {

    Account acct = Trigger.new[0];
     
//check to see if the Days Since Last Meaningful Conversation Date is greater than 120
    if(acct.Days_Since_Last_Activity_Modified_Date__c == 121){
      if(acct.Account_Rank__c == 'Sales Hot' || acct.Account_Rank__c == 'Sales Warm' || acct.Account_Rank__c == 'Sales Cool'){
      acct.Account_Rank__c = 'Needs Contact';
      }
     }
}

 Any suggestions would be greatly appreciated.

 

Thanks,

 

Christian

 

  • July 21, 2010
  • Like
  • 0

I have a trigger that works when I limit the Count query to only 1 where statement.  I am trying to figure out how to make it work with multiple criteria.

 

Code that works...

 

Integer accounts = [SELECT COUNT()FROM Account WHERE (Account.ownerId =: userInfo.getUserId())];

Code that doesn't work...

 

Integer accounts = [SELECT COUNT()FROM Account WHERE (Account.ownerId =: userInfo.getUserId()) AND (Account_Status__c NOT IN ('Current Customer', 'Seasonal - On', 'Seasonal - Off')) AND (Enb_Churn_Exclusion__c != null)];

Any ideas?

 

Thanks,

 

Christian

 

 

  • May 26, 2010
  • Like
  • 0

I am trying to create a new lead and task when a custom object called TPI_Supplier_Tracker__c is entered into the database.  I am getting null value errors and I think this is because the data hasn't been committed to the DB yet.  Here is the error I'm getting...

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger TPIEventCreateLeadTask caused an unexpected exception, contact your administrator: TPIEventCreateLeadTask: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]: Trigger.TPIEventCreateLeadTask: line 23, column 13

 

Here is my code...

 

 

trigger TPIEventCreateLeadTask on TPI_Supplier_Tracker__c (before insert) {

//On entry of a new TPI_Supplier_Tracker__c record create a lead, associate it to a campaign, and assign a task
//TPI_Supplier_Tracker__c records will be created in mass once a week

List<TPI_Supplier_Tracker__c> tpiList = new List<TPI_Supplier_Tracker__c>();

for(TPI_Supplier_Tracker__c tpi :Trigger.new){
tpiList.add(tpi);

Lead lead = new Lead(
LastName = '[Unknown]',
Company = tpi.Account__r.Name,
OwnerId = tpi.Account__r.OwnerId,
Status = 'Open',
LeadSource = 'Other',
ERP_Accounting_System__c = 'Unknown',
Existing_EDI_Application__c = 'Unknown',
Potential_Trading_Partners__c = tpi.Related_to_Account__r.Name);
// tpi.addError('Error - ' + tpi);
insert lead;
}
}

 

If I uncomment the addError it shows that there is data...

 

Error - TPI_Supplier_Tracker__c:{Account__c=0016000000NpaBiAAJ, IsDeleted=false, Last_Product_Activity__c=2010-03-15 00:00:00, Related_to_Account__c=0016000000NpaBhAAJ, Data_Being_Put_Into_TPI__c=true}

 

I want to assign the Lead.Name and Lead.OwnerId using information from the account related to the TPI_Supplier_Tracker__c record.  Is this possible and how can I access that information when the system is saying that they are blank?

 

Thanks,

 

Christian

 

 

  • March 15, 2010
  • Like
  • 0

I have a trigger that I created on Email Message that populates a date in the parent case of the most recent email message created date.  This allows me to run a workflow that reopens a case if an email comes in after the case has closed.  Here is the code for the trigger.

 

 

trigger LastEmailDateTime on EmailMessage (after insert) { EmailMessage email = Trigger.new[0]; //Populate the case with the Last EmailMessage CreatedDate value for(EmailMessage em:[Select CreatedDate, ParentID from EmailMessage where Id = :email.Id limit 1]){ for(Case c:[Select Id, Last_Email_Date_Time__c from Case where Id = :em.ParentId limit 1]){ c.Last_Email_Date_Time__c = em.CreatedDate; update c; } } }

 

 I recently installed the Case Age in Business Hours app.  Since I did that I am getting script exception errors for too many SOQL queries.  Here is an example of the error I receive.

 

 Developer script exception : LastEmailDateTime : LastEmailDateTime: execution of AfterInsert  caused by: System.Exception: Too many SOQL queries: 22  Trigger.LastEmailDateTime: line 7, column 23

 

Any suggestions on how I can reduce the number of SOQL queries?

 

Thanks!

 

  • March 01, 2010
  • Like
  • 0