• samd
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 20
    Replies

I've come across a strange issue where the user's language seems to affect the way that results are retrieved when querying the ProcessInstanceWorkItem table with SOQL.  I'm using the Apex code below inside a trigger to query the ProcessInstanceWorkItem table and create a map to see whether any of the records in the trigger are currently involved in an approval process.

 

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status like 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

When this code is triggered by a user with Language = English, this code works perfectly.  However, when the same code is triggered by a user with Language = Japanese, the code doesn't work as expected and doesn't return any records even when the record is actually inside an approval process.  After investigation I discovered that that if I change the SOQL query selection criteria to have ProcessInstance.Status = 'Pending' instead of ProcessInstance.Status like 'Pending' as shown below, then the code behaves as expected.

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status = 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

I can understand the translation workbench may affect SOQL results for certain fields, but I would expect system tables such as the ProcessInstanceWorkItem to return the same results regardless of the user's language settings. 

 

I've managed to work around this problem for now by using "=" instead of "like" inside the selection criteria, but I'd be very interested to know why this is necessary.

 

Sam

 

  • April 11, 2011
  • Like
  • 0
Hi

I have created the S-Control below to override the delete button for tasks.  The idea is that tasks with a "Lead Follow Up" record type cannot be deleted, but all other record types should be deleted as per a normal delete operation.  The problem is that I don't know what to use for the retURL shown in red below.  The "Action.Task.View" is clearly incorrect since the task will have been deleted when that action is called.  I need to be able to get back to the page from where the delete was called.  Is there any way of doing this?

Many thanks
Sam


Code:
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script language="JavaScript">

function initPage()
{
if ("{!Task.RecordType}" == "Lead Follow Up")
{
alert("Lead Tasks cannot be deleted. Lead Tasks are closed when converted to an opportunity or when rejected.");
history.go(-1);
}
else
{
window.parent.location.href = "{!URLFOR($Action.Task.Delete, Task.Id , [retURL=URLFOR($Action.Task.View, Task.Id)],true)}";
}
}

</script>
</head>
<body onLoad="initPage()">
</body>
</html>

 

  • August 06, 2008
  • Like
  • 0

I need to export a report as a CSV to an FTP site or email it on a daily or weekly basis.

 

I have a Report.  I need to get the report out of Salesforce somehow into CSV format.

 

Ideally, this would be scheduled.


I'm a developer so I can do developer stuff.  However, I don't know APEX and I don't know VisualForce.  I can get someone to do that stuff if we need to.


Thanks!

  • July 26, 2011
  • Like
  • 2

I am facing this issue these day and I also got the idea from community to solve it, but still I am not very much clear with the solution.


My scenerio is :

List<Lead> listLead = [Select Id from lead where Name IN : setNames];


and I am getting exception :

"System.QueryException: Non-selective query against large object type".

 

Now the solution says :

1. it's best to try to have that field indexed by checking the "external ID" checkbox when you define that field.

 Question:  In my scenerio we are quering the data using the native Name field, Can this field be marked as "External Id" ?

 

2filter out nulls in your Apex query. 

Question: Name field can not be null for lead, then how this statement can be meaningful? 

Please suggest.


Regards,

Bhawani

I've come across a strange issue where the user's language seems to affect the way that results are retrieved when querying the ProcessInstanceWorkItem table with SOQL.  I'm using the Apex code below inside a trigger to query the ProcessInstanceWorkItem table and create a map to see whether any of the records in the trigger are currently involved in an approval process.

 

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status like 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

When this code is triggered by a user with Language = English, this code works perfectly.  However, when the same code is triggered by a user with Language = Japanese, the code doesn't work as expected and doesn't return any records even when the record is actually inside an approval process.  After investigation I discovered that that if I change the SOQL query selection criteria to have ProcessInstance.Status = 'Pending' instead of ProcessInstance.Status like 'Pending' as shown below, then the code behaves as expected.

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status = 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

I can understand the translation workbench may affect SOQL results for certain fields, but I would expect system tables such as the ProcessInstanceWorkItem to return the same results regardless of the user's language settings. 

 

I've managed to work around this problem for now by using "=" instead of "like" inside the selection criteria, but I'd be very interested to know why this is necessary.

 

Sam

 

  • April 11, 2011
  • Like
  • 0

So, I have an Apex class that uses version 10.0 of the API (Summer '07) and it references a standard SF field called UserPermissionsAvantgoUser. I can't find reference to this anywhere else but here.


Yesterday (19th May) I started receiving Apex exceptions that stated that the field does not exist, which appears to be true if you look at the meta-data for the user object.


Simple, you might think; just remove the field from the class definition in a sandbox and deploy to production through eclipse. Unfortunately, SF won't let me overwrite the class, because, according to the validation error, the original class in production is referencing a non-existant field. Catch 22...


Apart from breaking a critical web app that we've built around this class, it is also disrupting normal operation of SF because we have triggers firing on contact edits which get stuck in the invalid code, even though the triggers only apply to a subset of contacts. I'm not a happy bunny.


I've raised a support case and hope to hear back ASAP, but was wondering if anyone else has been hit by this silent change to the backwards compatibility of the API? Any workarounds for when you are denied a class overwrite due to invalid code in production?

Message Edited by pastusobrown on 05-20-2009 11:06 PM

I created a send email class that accepts a bunch of parameters. It's currently used by two visualforce pages and 1 trigger/class.

 

The trigger/class setup is currently failing when I deploy to production. However, when I run the tests in the sandbox it comes back completely fine. The trigger is fired on an update of a case. When I update the case to fire the trigger - I get the expected result (an email).

 

I am creating my objects in the test class - except my Email Template and SF user (which are in both sandbox and production). All other objects - Account, Contact, and Case are created in the test class directly.

 

I added a system.debug('THIS IS THE MAIL:" + mail); to my send email class and this is what I see in the debug log when I deploy.

 

20090417151127.818:Class.Send_Single_Email_Class.SendEmail: line 111, column 9: THIS IS THE MAIL:Messaging.SingleEmailMessage[getBccAddresses=();getCcAddresses=();getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getPlainTextBody=null;getTargetObjectId=005700000017EbwAAE;getTemplateId=00X70000001F7ESEA0;getToAddresses=(support@pharmacyonesource.com);getWhatId=50070000008R2QFAA0;isUserMail=false;] System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null

 

 

You can see it stats Unknown_Exception - then tells me a parmaeters is null. I've compared these lines to a successful test that's run (using the same class but on different objects) - and with the exception of the TemplateID (not used) and the specific Email Address/WhatID it looks 100% the same.

 

I thought it might be my template problem - but I'm setting it like this

***Trigger's Class*** EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; ID TemplateID = ThisTemplate.Id; ***Send Email Class*** mail.setTemplateId(TemplateID); system.debug('Template is Valid: ' + TemplateID);

 

I'm really scratching my head on this one. I figured I must be missing something when I pass things over. But the SendEmail class works with my visualforce pages - just not this Trigger/Class. The main difference is I'm using a template ID and not setting the mail.setToAddresses to anything other than null.

 

Current UnitTest - The Trigger loops through trigger.new and assigns to variables the items passed over to each send email.

 

static testMethod void testTriggerCase_Interface_Before_Insert_Before_Update() 
{
	RecordType CaseRecordType = [Select r.SobjectType, r.Id, r.DeveloperName From RecordType r where r.DeveloperName='Standard' and sObjectType = 'Case'];
	User CSRQueue = [Select u.Username, u.UserRoleId, u.ProfileId, u.ManagerId, u.LastName, u.IsActive, u.Id, u.FirstName, u.Name,u.Email, u.CommunityNickname, u.Alias From User u where u.Id = '005700000017Ebw' and u.IsActive = True limit 1];
			
		Account NewAccount1 = new Account(name='Test Code Account',
			Hospital_Bed_Size__c = -1,
			BillingStreet = '7780 Elmwood Ave',
			BillingCity = 'Middleton', 
			BillingState = 'WI', 
			BillingPostalCode = '5356'
	   	);
	        insert NewAccount1;
		Contact NewContact = new Contact(
	   		LastName='Test',
	   		firstname='Contact',
	   		Email=CSRQueue.Email,
	   		AccountId = NewAccount1.id
	   	);	
	   	insert NewContact;	    
		Implementation__c NewS7IF = new Implementation__c 
	   	(
	   		RecordTypeId = '012500000009EQZ',
	   		Name = 'Test Code Implementation',
	   		Account__c = NewAccount1.id,
	   		//i.Product__c = 'Unit Stock',
	   		Sale_Date__c = date.Today(),
	   		Implementer__c = '005700000017Ebw', //CSR Queue   			
	   		Action_Requirement__c = 'POS',
	   		Stage__c = 'Initiation',
	   		Status__c = 'Moving Along',
	   		Status_Reason__c = 'N/A',
	   		Product__c = 'Sentri7 Interfaces',
	   		Interface_Products__c = 'Quantifi',
	   		Feed_Status__c = 'No Data Received Yet'
	   	);	
	   	insert NewS7IF;	   	
		Case NewStandardCase = new Case
		(
		  OwnerId = '005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id,
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger',
		  RecordTypeId = CaseRecordType.Id		
		);
		Case NewStandardCase2 = new Case
		(
		  OwnerId = CSRQueue.ID, //'005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id, 
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger2',
		  RecordTypeId = CaseRecordType.Id		
		);
		list<case> InsertCases = new list<case>();
		
		InsertCases.add(NewStandardCase);
		InsertCases.add(NewStandardCase2);			
		insert InsertCases;
		
        NewStandardCase.Notification_to_Owner__c = 1;
        NewStandardCase2.Notification_to_Owner__c = 0;
        list<case> UpdateCases = new list<case>();
        UpdateCases.add(NewStandardCase);
        UpdateCases.add(NewStandardCase2);        
        update UpdateCases;	
				
	} 

 

The Class that calls the SendEmail Class - this is done on a before update. Trigger is fired before update of case, and only cases with Notification_To_Owner__c set to 1 are sent to the NotificationToOwner class method below. The class loops through the list pulling the information and sending the e-mail and also returns the value to Notification_To_Owner__c to 0.

There's a lot of "empty" variables here since they get passed in other classes that use the SendEmail class. When I tested it doesn't appear that anything goes wrong if these are null as long as the required items are also present. (Example either a TemplateID or a HTMl/Plain body)

 

public static void NotificationToOwner(list<case> TheseCases) { set<id> OwnerID = new set<id>(); for(case c: TheseCases) { OwnerID.add(c.OwnerID); } map<id, User> MapUsers = new map<id,user>([Select u.Title, u.ManagerId, u.Id, u.Email From User u where u.id in :OwnerID]); /*Required SendEmail Variables */ list<string> ToEmail = new list<string>(); Contact eContact; list<string> CC = new list<string>(); list<string> BCC = new list<string>(); Boolean eAttach = False; Blob eAttachment; string eName; Boolean Activity = False; ID WhatID; Boolean Attach = False; String aName; String eSubject; String eBody; list<ID> DocAttach = new list<ID>(); EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; /*This template is present in both Sandbox and Production with the SAME developername */ ID TemplateID = ThisTemplate.Id; ID TargetObjectId; //list<case> UpdateCases = new list<case>(); /*Loop through cases and send Email */ for(case c: thesecases) { ToEmail.Clear(); //ToEmail.add(MapUsers.get(c.OwnerID).Email); WhatID = c.id; TargetObjectID = c.OwnerID; c.Notification_to_Owner__c=0; system.debug('Case Number, Case ID: ' + c.CaseNumber +' ID: '+ c.ID); system.debug('Email Variable OwnerID: ' + c.OwnerID); system.debug('Email Variable Email: ' + ToEmail); system.debug('Email Variable Case WhatID: ' + WhatID); Send_Single_Email_Class.SendEmail(ToEmail,eContact, CC,BCC, eAttach, eAttachment,eName, Activity,WhatId,Attach, aName,eSubject,eBody,DocAttach,TemplateID,TargetObjectID); } }

 

Hi

I have created the S-Control below to override the delete button for tasks.  The idea is that tasks with a "Lead Follow Up" record type cannot be deleted, but all other record types should be deleted as per a normal delete operation.  The problem is that I don't know what to use for the retURL shown in red below.  The "Action.Task.View" is clearly incorrect since the task will have been deleted when that action is called.  I need to be able to get back to the page from where the delete was called.  Is there any way of doing this?

Many thanks
Sam


Code:
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script language="JavaScript">

function initPage()
{
if ("{!Task.RecordType}" == "Lead Follow Up")
{
alert("Lead Tasks cannot be deleted. Lead Tasks are closed when converted to an opportunity or when rejected.");
history.go(-1);
}
else
{
window.parent.location.href = "{!URLFOR($Action.Task.Delete, Task.Id , [retURL=URLFOR($Action.Task.View, Task.Id)],true)}";
}
}

</script>
</head>
<body onLoad="initPage()">
</body>
</html>

 

  • August 06, 2008
  • Like
  • 0
Hi,

This is a simple question, is there a visual force element for lookup fields. I'm looking at the Visual Force component reference but can't find one, maybe I'm blind. Anyone know if I'm looking for something that doesn't exist?

Thanks,

Scott

Hi, I'm coding visualforce page.

I want to implement picklist item by visualforce but I cant see picklist tag element with visualforce reference guide..

Does anyone know how to code it or Should I write picklist code by javascript in <script> tag??

Thank you very much

I'm getting an error in trying to write a Test method that will compile. I started with the sample test code from the VF Developer's Guide. Here's my code:
 

public class newIP_Extension{
    
     private
final IP__c ip;

     public newIP_Extension(ApexPages.StandardController stdController){
          this.ip = (IP__c)stdController.getRecord();
     }

     <SNIP - many methods>

     public static testMethod void test_newIP_Extension(){
          Test.setCurrentPageReference(new PageReference('Page.newIP'));

          newIP_Extension controller = new newIP_Extension('IP__c'); 
          String nextPage = controller.continueToNext().getUrl();

          <SNIP various tests>
     }

}

This is the error I get "Error: Compile Error: Constructor not defined: [newIP_Extension].<Constructor>(String) at line 148 column 38 ."

If I don't pass 'IP__c' (the name of the standard controller) into the constructor I get "Error: Compile Error: Constructor not defined: [newIP_Extension].<Constructor>() at line 148 column 38 ."

If I don't quote IP__c I get "Error: Compile Error: Variable does not exist: IP__c line 148 column 58. "

The only difference between my code and the sample code is that the sample code is for a custom controller (rather than extension) and thus the controller doesn't have any parameters. What am I missing here?

Thanks for any insights!

  • March 11, 2008
  • Like
  • 0
I have written a C# application that forces territory rules to run on a scheduled time period by running the salesforce generated URL.  So I am trying to write a trigger that runs the territory rules when an Opportunity is either created or updated!  The problem is that I don't see a way to force the territory rules to run! 

Does any one have a practical solution?  BTW, I tried to update the account associated with the opportunity.  If I do it via Salesforce, the account page layout forces the territory rules to run.  This is due to the checkbox 'Run territory Assignment Rules on save by default' on the account page layout.  But, it seems this doesn't work via the API.

Any information on this matter would be greatly appreciated!
Hi,

I have enabled inline editing feature in my SFDC instance which works fine for all the objects. I tried overriding New/Edit button on Opportunity  which calls an  S-Control and takes back to the Opportuinty Layout after  processing. Once the S-Control moves back to the Opportunity, Inline Editing feature gets disabled for that opportunity and it doesnt works.

Should we pass on some hidden parameter to the opportunity page while transfering control to the opportunity which keeps that inline editing feture enabled?

Please suggest..

Thanks in advance.


Message Edited by GreatG on 12-20-2007 03:03 AM
  • December 20, 2007
  • Like
  • 0