• rscott
  • NEWBIE
  • 340 Points
  • Member since 2009

  • Chatter
    Feed
  • 11
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 43
    Replies

 

//this will fail reporting a size of 0
string s = 'first.second';
string[] part;
part = s.split('.');
System.DEBUG(part.size());

//this will work reporting a size of 2
string s = 'first_second';
string[] part;
part = s.split('_');
System.DEBUG(part.size());

 

I'm usign API version 20. Paste this into the Execute Anonymous window of the IDE. Anyone have any ideas?

 

I am writing a test class and am running into this error:

Error: Compile Error: Illegal assignment from SOBJECT:Customer_Product__c to Id at line 11 column 9

 Here is my test class:

@isTest
private class BulkDensityTest{
    testmethod private static void TestTrigger() {
        Customer_Product__c cp = new Customer_Product__c
            (name = 'apple');
        insert cp;
        
        Customer_Bulk_Density__c  c = new Customer_Bulk_Density__c ();
        c.Name = '4';
        c.Metric_Label__c = 'kg/m3';
        c.Customer_Product__c = cp;
        insert c;
        
        System.debug('c:' + c);
        c = [SELECT ID, Name FROM Customer_Bulk_Density__c  WHERE id = :c.id];
        System.debug('c:' + c);
        System.assertEquals(c.Customer_Product__c, c.Name);
        Profile p = [select id from profile where name='Standard User'];

    User u = new User(alias = 'standt', email='standarduser@testorg.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
System.runAs(u) {
// The following code runs as user 'u'
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId()); }
}
     

}

 

Here is the trigger:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
    Set<Id> bIds = new Set<Id>();

list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();

if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute);
    for(Customer_Bulk_Density__c c:trigger.new)
    {
     bIds.add(c.id);
     
     if(c.Metric_Label__c =='Lbs./ft3')
     {
     Double conversion = Double.valueof(c.Name) * 16.018;
         Long L1 = conversion.round();
        
      Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Metric_Label__c = 'Kg/m3',
        Name = String.Valueof(L1) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        );
        customerBulkDensityList.add(s);   
        }
         else
        {
         Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
              Long L2 = conversion1.round();        
              
         Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
         
        Metric_Label__c = 'Lbs/ft3',
        Name = String.Valueof(L2) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        
        );
        customerBulkDensityList.add(s);   
        } 
    }
    StaticClass.doNotExecute =false;
    if(!customerBulkDensityList.isEmpty())
    {
        insert customerBulkDensityList;
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
 
  }
  else
  {
  StaticClass.doNotExecute =true;
  }

  }

 

How to I solve the error?

 

Thank you again

  • August 02, 2010
  • Like
  • 0

Hi,

 

Using the Database DML property SaveResult along with the for loop to retrieve list of the error messages pertaining to the records that did not get updated does not do me a whole lot of good without knowing the record ID!!!


I have found others having the difficulty of accepting that this is the nature of the DML property SaveResult.  If it is used to Insert I can understand you would not have an ID on a record that did not get inserted but this about existing records with an ID.

 

Does anyone know a work around still using the code:

 

Database.SaveResult[] results = Database.Update(opps, false)

 

that would allow me to include the ID in my email.  I need to be able to research the record in order to troubleshoot the "Why didn't the record update?" question.

 

Thanks in advanced.  Troubles and work arounds exist in all languages but Apex needs to catch up to the big league languages like C# and java.  That is just a want-a-be programmer's perspective.  In the mean time I am having a blast learning SFDC as a whole.

 

You guess make it that much more desirable to learn.

 

 

Hi,

I m trying to get all the values of a picklist (custom field) using apex, but still i couldn't.

Is there any way to do it ?

If you have, pls reply......

 

 

Thanks.

 

     List<Task> histories = [Select id,Ownerid,whatid,whoid,activitydate,subject,website__c From Task where (whatid=:relatedLink.id and Ownerid=:currentUser and Status='Not Started') limit 1]; 

 

 

 

I'm getting an exception when deploying that is telling me  "Too many query rows: 501".

 

Doesn't the "Limit 1" take care of this??

 

Thanks!

  • July 06, 2010
  • Like
  • 0

Hey All,

Following a guide online I found how to make a class that will query for data and get the results to JSON for me, it's very cool. But I do not understand how it works. It's basically laid out like this

 

 

public class getJsonEvents { public JsonObject json {get;set;} /** invoked on an Ajax request */ public void getEvents() { //Code to build json string } // Returns the JSON result string public String getResult() {

  string jsonString = json.ValuetoString();

return jsonString; } }

 The first method is void, and the 2nd returns the string. The visual force page that calls and uses it successfully looks like this.

 

 

<apex:page controller="getJsonEvents" action="{!getEvents}" contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false"> {!result} </apex:page>

 

 So it has the class set as it's controller, and it calls getEvents. Makes sense so far, except that it never calls getResult().

 

Nowhere is getResult invoked that I can find, yet the results get printed. More confusing is that this {!result} variable comes out of seemingly nowhere. I never created it, I never named it, but somehow it's there. I guess that is the default name of the return contents of the controller?

 

When uses this way does all code in a class just run sequentially until it hits a return statment or what? Also, how can I test this?I tried using code like this

 

//Create page reference PageReference opsCalendar = Page.OpsCalendar; //Pass start and end timestamps in url opsCalendar.getParameters().put('start','1262332800'); opsCalendar.getParameters().put('end','1263178646'); //initiate page reference Test.setCurrentPageReference(opsCalendar); //create instance of the class getJsonEvents eventsCtlr = new getJsonEvents(); //This fails because getEvents returns null; can't assign that to string myRunResult = eventsCtlr.getEvents(); //log the results System.Debug('get JSON Events result'+myRunResult );

 but it doesn't work, as i end up trying to assing the results of a null method/function to a string. What do I do?

 

Any help is appreciated. I know these are dumb questions, but at least I'm learning :P Thanks again.

 

 

 

 

Quick query - I have 80% code coverage on my apex class yet my overall coverage is 70% as it is including my test method....do I need unit tests for my test methods ?

I'm working on some unit test coverage code and currently have 77% of the controller covered.  I'm trying to get the remaining lines covered before adding my assert statements.

 

The lines missing code coverage are in my save() method (see the screenshot below).

 

In my test method, I've initialized the controller and passed in a new instance of the StandardSetController with a list of the sObject being used.  I have called all the properties and methods in the controller.

 

Can anyone provide some help on how I can get the missing lines in my save method covered?  I need to create a new task to use in the save method that is being attached to multiple records.

 

Here is my controller code:

 

public class MassAddActivityController { private List<Service_Delivery__c> sds; private Task assignedTo = new Task(); private Task status = new Task(); private Task activityDate = new Task(); private Task clientAttendees = new Task(); private Task hsgAttendees = new Task(); private Task presenter = new Task(); private Task purpose = new Task(); private Task dynamics = new Task(); private Task outcomes = new Task(); private Task description = new Task(); private Task sendContactReport = new Task(); private Boolean render; private Integer count; public Task task {get; set;} public Task getAssignedTo() { return assignedTo; } public Task getStatus() { return status; } public String subject { get; set; } public Task getActivityDate() { return activityDate; } public Task getClientAttendees() { return clientAttendees; } public Task getHsgAttendees() { return hsgAttendees; } public Task getPresenter() { return presenter; } public Task getPurpose() { return purpose; } public Task getDynamics() { return dynamics; } public Task getOutcomes() { return outcomes; } public Task getDescription() { return description; } public Task getSendContactReport() { return sendContactReport; } public MassAddActivityController(ApexPages.StandardSetController stdSetController) { init((List<Service_Delivery__c>) stdSetController.getSelected()); status.status = 'Completed'; subject = 'Presentation/Meeting'; assignedTo.OwnerId = UserInfo.getUserId(); DateTime dt = System.now(); Date currentDate = date.newinstance(dt.year(), dt.month(), dt.day()); activityDate.activityDate = currentDate; render = false; } public void init(List<Service_Delivery__c> sds) { List<Id> ids = new List<Id>(); for (Service_Delivery__c sd : sds) { ids.add(sd.id); } this.sds = [Select Id, Name From Service_Delivery__c Where Id in :ids]; count = [Select Count() From Service_Delivery__c Where Id in :ids]; } public Id getRecordTypeId() { RecordType rt = [Select Id From RecordType WHERE Name = 'Contact Reports Entry']; Id recordTypeId = rt.Id; return recordTypeId; } public List<Service_Delivery__c> getServiceDeliveries() { return sds; } public List<SelectOption> getItems() { Schema.DescribeFieldResult pklst = Schema.Task.Subject.getDescribe(); List<Schema.PicklistEntry> ple = pklst.getPicklistValues(); List<SelectOption> options = new List<SelectOption>(); for(Schema.PicklistEntry f : ple) { options.add(new SelectOption(f.getLabel(), f.getLabel())); } return options; } public PageReference save() { try { for (Service_Delivery__c sd : sds) { Task t = new Task(); t.recordTypeId = getRecordTypeId(); t.ownerId = assignedTo.OwnerId; t.status = 'Completed'; t.subject = subject; t.activityDate = activityDate.activityDate; t.whatId = sd.Id; t.Client_Company_Attendees__c = clientAttendees.Client_Company_Attendees__c; t.Health_Strategies_Group_Attendees__c = hsgAttendees.Health_Strategies_Group_Attendees__c; t.Meeting_Presenter__c = presenter.Meeting_Presenter__c; t.Purpose__c = purpose.Purpose__c; t.Dynamics__c = dynamics.Dynamics__c; t.Outcomes__c = outcomes.Outcomes__c; t.description = description.description; t.Send_Contact_Report__c = sendContactReport.Send_Contact_Report__c; t.Mass_Added_Date__c = Date.today(); insert t; } ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Activities added successfully.'); ApexPages.addMessage(msg); render = true; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public boolean getRendered() { return render; } public Integer getCount() { return count; } static testMethod void test() { List<Service_Delivery__c> sds = [Select id, name From Service_Delivery__c LIMIT 5]; MassAddActivityController ctrl = new MassAddActivityController(new ApexPages.StandardSetController(sds)); ctrl.getAssignedTo(); ctrl.getStatus(); ctrl.getActivityDate(); ctrl.getClientAttendees(); ctrl.getHsgAttendees(); ctrl.getPresenter(); ctrl.getPurpose(); ctrl.getDynamics(); ctrl.getOutcomes(); ctrl.getDescription(); ctrl.getSendContactReport(); ctrl.getCount(); ctrl.getRendered(); ctrl.getRecordTypeId(); ctrl.getServiceDeliveries(); ctrl.getItems(); ctrl.save(); } }

 

screenshot

screenshot

Hi,

 

I am trying to find out if there is any way to remove an Email service, as I can see no obvious way to do so.

 

This has become an issue because I have created a package that contains an Apex class that handles email messages.

 

I install the package in a development environment and create an Email service that uses that Apex class.  Everything works ok until I want to uninstall the package.  I can't because the Apex class is being used by the Email service, but I can't delete the Email service.

 

Any ideas?

 

Carl

  • September 08, 2009
  • Like
  • 0

Hello,

I am trying to send an Email using a visualforce template, with a pdf attachment, but can't seem to make it work. In my application i have a "sutTer__c" object, which is linked to a "traveller" object. This is a simplified version of the Email template:

 

<messaging:emailTemplate subject="TER" recipientType="User" relatedToType="sutTer__c">
<messaging:plainTextEmailBody >
Attached the TER details
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf" filename="ter.pdf">
    This is the Attachment fot Ter number&nbsp;
    <apex:outputText value="{!relatedTo.name}"/>
</messaging:attachment>   
</messaging:emailTemplate>

 

This is the code that should send the Email (at this point there is an object ter of the type sutTer__c):

        

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {ter.Traveller__r.user__r.Email});
mail.setTemplateId('00X800000018i7A');
mail.setWhatId(ter.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

However, when i try to send an Email with this code, i get an error massage:

"Missing targetObjectId with template."

So i set targetObjectId (and set the saveAsActivity to false,to prevent another error massage), and only then send the mail:

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {ter.Traveller__r.user__r.Email});
mail.setTemplateId('00X800000018i7A');
mail.setWhatId(ter.id);

mail.setTargetObjectID(ter.traveller__r.user__r.id);

mail.setSaveAsActivity(false);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

in this case the email is being sent, but it is empty (no body and no attachment). Can anyone tell me what am I doing wrong?

 

thanks,

 

Alon

 

 

 

 

Message Edited by alonm on 05-06-2009 02:24 AM
  • May 05, 2009
  • Like
  • 0

We have several Visualforce email templates defined in our managed package. Some of them reference a component in our managed package to create an attachment. All works well until, after we install the package, we try to modify the template to point to a new component in the installed org (not in the managed pkg). Then we get an error saying that it can't find the component.

 

The installed template still shows the component referenced as <c:compName/>. Both that and changing it to <namespace:compName/> reference the component in the managed package. Changing to <c:newCompName /> where newCompName is outside of the managed package gives us the afore-mentioned error. Seems like a bug to me or at least an oddity in how components are handled in managed email templates. Anyone else come across a similar issue?

  • February 11, 2011
  • Like
  • 1

I have the need to pre-populate certain data fields on a standard custom object page. The data will come from a Visualforce page. I have seen several posts detailing how to do this using the field Id. However, I need to package this code and install in various other orgs which will all have different field Ids. Some of these posts claim that the packaging mechanism will modify the field Ids to fit the target org, but I can't seem to get that to work. 

 

 

<apex:commandButton action="{!URLFOR($Action.Test_Line__c.New, null)}&CF00NA0000004cg8S={!Test__c.Name}" value="New Test Line" />

This is trying to add a new Test Line object that references an existing Test object. The field Id for Test__c.name is 00NA0000004cg8S. The "CF" gets prepended to make the control Id on the page.

 

There doesn't seem to be a programmatic way to get field Ids. And I don't see how the packaging system can recognize that "CF00NA0000004cg8S" is a field Id in order to replace it. Is there another way to do this that will result in a successful field Id replacement?

 

 

 

 

  • October 08, 2010
  • Like
  • 0

I am trying to create an autocomplete field on a Visualforce page using jQuery autocomplete. Everything works fine in Firefox and Chrome. Everything works fine in IE, until some other AJAX calls make it onto the page (i.e. putting a rerender attribute on a commandButton, adding an actionRegion tag, etc) I'm not sure why. I'm getting no javascript errors in Firefox or IE. Anyone have any ideas or a workaround?

 

Here's some sample code:

 

 

<apex:page controller="TestController">

	<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jquery-1.4.2.min.js')}" />
	<apex:includeScript value="{!URLFOR($Resource.jQuery, 'jquery-ui-1.8.5.custom.min.js')}" />
    <apex:stylesheet value="{!URLFOR($Resource.jQuery, 'css/cupertino/jquery-ui-1.8.5.custom.css')}"/>

	<script type="text/javascript">
	var j$ = jQuery.noConflict();
	
    j$(function() {  

        j$("#autoc").autocomplete({
        
            source: function(request, response) {
                    j$.getJSON("{!$Page.lookup}", {
                        term: request.term
                    }, response);
                },
        minLength: 2
            
        });
    });
    </script>

<apex:form >

    <apex:sectionHeader title="jQuery Test" />

    <apex:pageblock id="pb">
		<apex:pageBlockSection title="Block One">
			Account Autocomplete: <input type="text" id="autoc" />
			<apex:commandButton value="Do Something" action="{!doSomething}" rerender="pb" />
		</apex:pageBlocksection>
    </apex:pageblock>
    
</apex:form>
</apex:page>

The lookup page just returns JSON formatted data based on the entered text.

 

Take away the rerender attribute on the button and everything works fine in all browsers. Add it back and it fails only in IE.

 

  • October 08, 2010
  • Like
  • 0

We have a managed package with many custom objects. Now, we are creating a package extension. This extension has some new custom fields added to several custom objects in the managed package. They package up just fine, the issue is getting an updated .object file so we can add it to our source control database (subversion). 

 

I am able to get updated standard objects we've added fields to (Eclipse > Force.com Project Contents, add objects - standard), but not custom objects. How can I get these updated files?

  • September 08, 2010
  • Like
  • 0

I just downloaded the new Force.com Explorer (beta). I can log in and see my schema. The problem is that when I expand an object, I don't see any child relationships or fields. I can run a query if I manually enter it, but the database schema section is not working properly. I've tried connecting to multiple clouds with the same issue. Anyone else having the same problem?

  • August 02, 2010
  • Like
  • 0

I having an issue with encrypted fields not saving. Weird issue. Here's how to reproduce it:

 

1. On a custom object, create an encrypted text field. Mask Type = Mask All Characters, Mask Character = *

 

2. Log in as a user whose profile does NOT include the permission 'View encrypted data'.

 

3. Save a record with a value in your new encrypted field.

 

4. Note what that value is either by logging in as someone who has the 'View encrypted data' permission or by doing some anonymous Apex. (or just remember what you typed in step #3, i guess)

 

5. Edit that same record, but only change the encrypted field and change it to another value with the same length.

ex. initial value = "Test123", change to "Test456". each value has 7 characters.

 

6. Find that value using the same method as #4. 

 

In my tests, the value found in #4 is the same as in #6.

 

If you edit the field with the 'View encrypted data' permission, it works fine. If the encrypted field is set with a mask of 'Last Four Characters Clear', it works fine. And if you also edit a different non-encrypted field at the same, it works fine. You have to have encryption turned on in your org, so if you don't you won't get past step 1. I'm curious if anyone else has experienced this or can reproduce it. Seems like a bug to me.

I'm trying to construct a dynamic query where the where clause comes in the page parameters. Not wanting to subject myself to possible SOQL-injection, I am using the escapeSingleQuotes method. However, this is causing an error when running the query: 

 

System.QueryException: line 1:76 no viable alternative at character '\'

 

Do I have something wrong or is this expected behavior? If it is expected, how would one go about solving this?

 

Edited code:

 

private List<sObject> getQuery(){
    string qry  = ApexPages.currentPage().getParameters().get('q');
    string objectName = ApexPages.currentPage().getParameters().get('object_name');
    string whereClause = ApexPages.currentPage().getParameters().get('where_clause');  

    string queryString = 'select Id, Name from ' + string.escapeSingleQuotes(objectName) + ' where name like \'%'+ string.escapeSingleQuotes(qry) + '%\'';
    if (whereClause.trim().length() != 0) {
	queryString +=  ' AND ' + string.escapeSingleQuotes(whereClause);
    }
    
    return Database.query(queryString);
}

If  the where_Clause parameter is Status__c='Open', the query becomes the following and I get the error.

 

select Id, Name from MyObject__c where name like '%ABC%' AND Status__c=\'Open\'


 

I created an email service that creates an attachment to a custom object. That attachment is based on the content of a Visualforce page. A PageReference gets created and then I take the content of that page and use it for the attachment body. Code is something like this:

 

PageReference pdfPage = Page.CustomerQuoteDisplay;

pdfPage.getParameters().put('id', quoteId);

Attachment attachment = new Attachment();

attachment.ParentId = quoteId;

attachment.name = 'QuoteSent';

attachment.body = pdfPage.getContent();

insert attachment;

  

This all works fine when similar code is initiated from a page action. However, in my InboundEmailHandler, getContent() returns this:  

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html><head>

<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>if (window.location.replace){ window.location.replace('https://login.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.na6.visual.force.com%252Fapex%252Fcustomerquotedisplay%253Fid%253Da0E80000003MySFEA0%2526inline%253D1%2526core.apexpages.devmode.url%253D1');

} else {

;window.location.href ='https://login.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.na6.visual.force.com%252Fapex%252Fcustomerquotedisplay%253Fid%253Da0E80000003MySFEA0%2526inline%253D1%2526core.apexpages.devmode.url%253D1';}

</script>

</head></html>

<!--............................................................................................................................................................................................................................................................................................................................................................................................................

-->

 

Basically, it's redirecting to the login page. If I pasted the url into a browser and logged in, it would take me to the page I want. I read an old post (01/09) that said getContent() was not supported in @future methods. Does the same apply to email handlers? Is the handler executed in some non-logged in context?

 

Thanks,

Rob 

 


 

  • April 01, 2010
  • Like
  • 0

We have a need to update an external system (through web service callouts) based on actions inside Salesforce. In order to limit the number of updates, we thought we could combine some updates together and use batch Apex. Unfortunately, there appears to be a limit in the number of callouts in batch Apex of one (1). The batch apex documentation states that it "uses the standard governor limits anonymous block, Visualforce controller, or WSDL method" which would give a limit of 10 callouts. This does not appear to be the case and the limit of 1 effectively forces a (fairly useless) max batch size of 1 in order to guarantee not hitting it. Has anyone hit this limit and used a different approach?

 

Also, does anyone know if there is a governor limit on the total number of callouts per day? I can't seem to find one in the docs.

 

Thanks,

 

Rob 

  • January 06, 2010
  • Like
  • 0

Requirement: Get the last 10 orders/quotes/etc. for each part on a new order.

ex. select Id from Order__c

where part='part1'

order by createddate desc

limit 10

 

The problem is if we make requests from 3 objects (orders, quotes, and item history, say) and we have more than 33 parts on the order, we hit the governor limit of 100 SOQL queries.

 

I would like to make one call to each object using an 'in' clause with a list of parts. However, I'm not sure how to get the last 10 for each part other than looping through the results (possibly quite large) until I get them. 

 

Any way to limit results for each item in a single query? Alternate ideas?

  • October 23, 2009
  • Like
  • 0

It looks like if you specify a templateId on a Messaging.SingleEmailMessage object, you must also specify a TargetObjectId. That's fine if you are sending to an existing contact or user, but what if you just have an email address? Can you send an email using a template and just specify an email address? If not, any ideas on how to leverage a template in this manner?

We have several Visualforce email templates defined in our managed package. Some of them reference a component in our managed package to create an attachment. All works well until, after we install the package, we try to modify the template to point to a new component in the installed org (not in the managed pkg). Then we get an error saying that it can't find the component.

 

The installed template still shows the component referenced as <c:compName/>. Both that and changing it to <namespace:compName/> reference the component in the managed package. Changing to <c:newCompName /> where newCompName is outside of the managed package gives us the afore-mentioned error. Seems like a bug to me or at least an oddity in how components are handled in managed email templates. Anyone else come across a similar issue?

  • February 11, 2011
  • Like
  • 1

 

//this will fail reporting a size of 0
string s = 'first.second';
string[] part;
part = s.split('.');
System.DEBUG(part.size());

//this will work reporting a size of 2
string s = 'first_second';
string[] part;
part = s.split('_');
System.DEBUG(part.size());

 

I'm usign API version 20. Paste this into the Execute Anonymous window of the IDE. Anyone have any ideas?

 

I have the need to pre-populate certain data fields on a standard custom object page. The data will come from a Visualforce page. I have seen several posts detailing how to do this using the field Id. However, I need to package this code and install in various other orgs which will all have different field Ids. Some of these posts claim that the packaging mechanism will modify the field Ids to fit the target org, but I can't seem to get that to work. 

 

 

<apex:commandButton action="{!URLFOR($Action.Test_Line__c.New, null)}&CF00NA0000004cg8S={!Test__c.Name}" value="New Test Line" />

This is trying to add a new Test Line object that references an existing Test object. The field Id for Test__c.name is 00NA0000004cg8S. The "CF" gets prepended to make the control Id on the page.

 

There doesn't seem to be a programmatic way to get field Ids. And I don't see how the packaging system can recognize that "CF00NA0000004cg8S" is a field Id in order to replace it. Is there another way to do this that will result in a successful field Id replacement?

 

 

 

 

  • October 08, 2010
  • Like
  • 0

We have a managed package with many custom objects. Now, we are creating a package extension. This extension has some new custom fields added to several custom objects in the managed package. They package up just fine, the issue is getting an updated .object file so we can add it to our source control database (subversion). 

 

I am able to get updated standard objects we've added fields to (Eclipse > Force.com Project Contents, add objects - standard), but not custom objects. How can I get these updated files?

  • September 08, 2010
  • Like
  • 0

I am writing a test class and am running into this error:

Error: Compile Error: Illegal assignment from SOBJECT:Customer_Product__c to Id at line 11 column 9

 Here is my test class:

@isTest
private class BulkDensityTest{
    testmethod private static void TestTrigger() {
        Customer_Product__c cp = new Customer_Product__c
            (name = 'apple');
        insert cp;
        
        Customer_Bulk_Density__c  c = new Customer_Bulk_Density__c ();
        c.Name = '4';
        c.Metric_Label__c = 'kg/m3';
        c.Customer_Product__c = cp;
        insert c;
        
        System.debug('c:' + c);
        c = [SELECT ID, Name FROM Customer_Bulk_Density__c  WHERE id = :c.id];
        System.debug('c:' + c);
        System.assertEquals(c.Customer_Product__c, c.Name);
        Profile p = [select id from profile where name='Standard User'];

    User u = new User(alias = 'standt', email='standarduser@testorg.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
System.runAs(u) {
// The following code runs as user 'u'
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId()); }
}
     

}

 

Here is the trigger:

 

trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
    Set<Id> bIds = new Set<Id>();

list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();

if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute);
    for(Customer_Bulk_Density__c c:trigger.new)
    {
     bIds.add(c.id);
     
     if(c.Metric_Label__c =='Lbs./ft3')
     {
     Double conversion = Double.valueof(c.Name) * 16.018;
         Long L1 = conversion.round();
        
      Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
        Metric_Label__c = 'Kg/m3',
        Name = String.Valueof(L1) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        );
        customerBulkDensityList.add(s);   
        }
         else
        {
         Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
              Long L2 = conversion1.round();        
              
         Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
         
        Metric_Label__c = 'Lbs/ft3',
        Name = String.Valueof(L2) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
        Customer_Product__c=c.Customer_Product__c,
        Customer_Product_2__c=c.Customer_Product_2__c,
        Customer_Product_3__c=c.Customer_Product_3__c
        
        );
        customerBulkDensityList.add(s);   
        } 
    }
    StaticClass.doNotExecute =false;
    if(!customerBulkDensityList.isEmpty())
    {
        insert customerBulkDensityList;
    }
    
    System.debug('****1 : B Id size '+ bIds.size());
 
  }
  else
  {
  StaticClass.doNotExecute =true;
  }

  }

 

How to I solve the error?

 

Thank you again

  • August 02, 2010
  • Like
  • 0

I just downloaded the new Force.com Explorer (beta). I can log in and see my schema. The problem is that when I expand an object, I don't see any child relationships or fields. I can run a query if I manually enter it, but the database schema section is not working properly. I've tried connecting to multiple clouds with the same issue. Anyone else having the same problem?

  • August 02, 2010
  • Like
  • 0

Hello everyone,

                             In the following piece of code I am unable to fetch the rows if the groupName consists of left open paranthesis '('  and right open paranthesis ')'.

 

for Eg: if groupName = Assisted Health program (AHP) Japan

 If i remove (AHP) then it is working fine. like if i have my groupname as 'Assisted Health Program'. I am able to fetch the rows.

 

So, how to fetch the rows even if it consists of paranthesis in the groupName?

 

 

 

this.groupName = ApexPages.currentPage().getParameters().get('group');
if (groupName != null) {
evs = [Select Time_Zone_Offset__c, Start_Time__c, Start_Date__c, Name, Id, End_Time__c From Offmax_cal__c where Business__c like :(groupName + '%')];

I'm trying to query something in a custom button JavaScript.  The query uses a reference field on the custom object record.  However the {!} returns with referenced object's name instead of id, so I can't use it in a SOQL statement.  For instance,with SFDC_Projects__c defined as a lookup/reference on SFL5_Time__c object,

soql=soql + "'{!SFL5_Time__c.SFDC_Projects__c}'";

gets 'steves project" instead of the id for the project.  Since I'm trying to find out another object that's related to the same project, I really need the id instead of the name.

 

The same way works just fine in APEX trigger.  What did I miss in the JavaScript/AJAX Toolkit environment?

  • August 02, 2010
  • Like
  • 0

I have a List Button placed on a related list which redirects to a VF page. The controller behind the VF page retrieves the list of selected options and the user then performs some operation on those options.

I would like to prevent the redirect to the VF page if the user has not selected any records. I've tried changing the button to a Onclick Javascript and I can detect whether or not there are any options selected, but I'm unable to then Submit their selection and redirect to the VF page. More precisely, I can submit and redirect to the VF page, but the selected options aren't recieved by the controller.

 

Is there a way to do this?

 

Here is the javascript on my List button

 

records = {!GETRECORDIDS($ObjectType.Job_Applicant__c)};

if (records.length < 1) {
  alert('Please select one or more options first.');
} else {
  this.form.action = '/apex/MyVFPage';
  this.form.submit();
}

 Appreciate any suggestions. Cheers.

 

Hello all,

I have created a visualforce page with a custom controller calls "Xcontroller". 

on my controller I have defined a member of my class "Y" like this:

 

"private static Y y = new Y(a,b);"

 

This line is executed on page load.

 

When I click on my page button "finish" I invoke the function I created in my controller called "finish".

 

In this function I call functions from my class y, for example:

 

public class y {

 

private static string z;

private static string A;

private static string B;

 

public y(string a, string b)

{

     A=a;

     B=b;

}

 

public string getZ()

{

return z;

}

 

public static void setZ(string zz)

{

    z=zz;

}

 

}

 

 

on my controller :

public with sharing class Xcontroller{

 

private static Y y = new Y(a,b);

 

public Xcontroller()

{

}

 

public pagereference finish()

{

string w= y.getZ();

}

 

 

the problem is that when I click on "finish" the value in 'w' is null although on the page load before it got a value!

 

Can anyone help me understand what I did wrong?

Thanks a lot,

Inbal

 

 

can anybody help me how to pass the javascript values to a  controller in a visualforce page

Here's the situation...

 

We have an external application that collects various data.  We like to have clients install an app in their Org that allows us to import data into their org without us having to collect a user/pass from them.

 

It seems like the partner API should be able to do this, but can't find it documented anywhere.

 

Thanks for any help.

Brian

visual force page:


<apex:page standardController="Quotation__c" extensions="sendEmail1" sidebar="false">
<apex:sectionHeader title="Quotation Information Form" printUrl="https://cs5.salesforce.com/apex/QuotePdf?id={!$CurrentPage.parameters.id}&sfdc.override=1"/>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Quotation Details" columns="1">  
                                     
                 <apex:outputField value="{!Quotation__c.Name}"/>
                <apex:outputField value="{!Quotation__c.To__c}"/>
               
               <apex:outputField value="{!Quotation__c.Address__c}"/>
               <apex:OutputField value="{!Quotation__c.Kind_Attn__c}"/>
               <apex:OutputField value="{!Quotation__c.Dear_Sir__c}"/>
               <apex:OutputField value="{!Quotation__c.Notes__c}"/>
               <apex:OutputField value="{!Quotation__c.Terms_and_Conditions__c}"/>
               <apex:OutputField value="{!Quotation__c.Items_Selected__c}"/>
                
                
            
            
               <!-- <apex:outputField value="{!Quotation__c.Items_Selected__r.Name}"/>
                <apex:outputField value="{!Quotation__c.}"/> -->
                
            </apex:pageBlockSection>
        </apex:pageBlock>

       
<apex:dataTable value="{!itemSelected}" var="fcst" width="100%" >
<apex:column width="8%" ><apex:facet name="header">Product</apex:facet><apex:outputLabel value="{!fcst.Product__r.name}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Item Description</apex:facet><apex:outputLabel value="{!fcst.Item_Description__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Unit Price</apex:facet><apex:outputLabel value="{!fcst.Unit_Price__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Quantity</apex:facet><apex:outputLabel value="{!fcst.Quantity__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Total Price</apex:facet><apex:outputLabel value="{!fcst.Total_Price__c}" /></apex:column>


</apex:dataTable>
<apex:commandButton value="send" action="{!send}"/>
       
    </apex:form>        
</apex:page>



Apex Controller:

 

public class sendEmail1
{
public Quotation__c quot;
public sendEmail1(ApexPages.StandardController controller)
 {
 }
 public sendEmail1()
 {
 quot=[select Id,To__r.Email from Quotation__c where id=:ApexPages.currentPage().getParameters().get('id')];
 }

public List<Items_Selected__c> getitemSelected ()
{
List<Items_Selected__c> ISRL =[select Product__r.name,Quantity__c,Item_Description__c,Unit_Price__c,Total_Price__c from Items_Selected__c where Quotation__c =: ApexPages.currentPage().getParameters().get('id')];
return ISRL;
}

public PageReference send()
{
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        PageReference pdf = Page.QuotePdf;
        pdf.getParameters().put('id',(String)quot.Id);
        pdf.setRedirect(true);
        Blob b = pdf.getContent();
        Messaging.EmailFileAttachment efa=new Messaging.EmailFileAttachment();
        efa.setFileName('attachment.pdf');
        efa.setBody(b);
        String address=quot.To__r.Email;
        email.setToAddresses(new String[]{address});
        email.setFileAttachments(new Messaging.EmailFileAttachment[]{efa});
        Messaging.sendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
        return null;
        
        }
        }

 


When the save Button is clicked,it is producing a Error as :ATTEMPT TO DEREFERENCE A NULL OBJECT.

 

Can i know where the problem had occured..

Hi,

 

Using the Database DML property SaveResult along with the for loop to retrieve list of the error messages pertaining to the records that did not get updated does not do me a whole lot of good without knowing the record ID!!!


I have found others having the difficulty of accepting that this is the nature of the DML property SaveResult.  If it is used to Insert I can understand you would not have an ID on a record that did not get inserted but this about existing records with an ID.

 

Does anyone know a work around still using the code:

 

Database.SaveResult[] results = Database.Update(opps, false)

 

that would allow me to include the ID in my email.  I need to be able to research the record in order to troubleshoot the "Why didn't the record update?" question.

 

Thanks in advanced.  Troubles and work arounds exist in all languages but Apex needs to catch up to the big league languages like C# and java.  That is just a want-a-be programmer's perspective.  In the mean time I am having a blast learning SFDC as a whole.

 

You guess make it that much more desirable to learn.

 

 

Hi,

I m trying to get all the values of a picklist (custom field) using apex, but still i couldn't.

Is there any way to do it ?

If you have, pls reply......

 

 

Thanks.

 

     List<Task> histories = [Select id,Ownerid,whatid,whoid,activitydate,subject,website__c From Task where (whatid=:relatedLink.id and Ownerid=:currentUser and Status='Not Started') limit 1]; 

 

 

 

I'm getting an exception when deploying that is telling me  "Too many query rows: 501".

 

Doesn't the "Limit 1" take care of this??

 

Thanks!

  • July 06, 2010
  • Like
  • 0

Hey,

 

I was looking to enhance user experience by providing some better error messages. The one I am trying to overload now, is where it does not have an ID it needs in the URL, so rather than saying 'List out of bounds', I would like to explain to users that they need to go back and select a new ID to continue. I tried the following:

LIST<Model_Definition__c> temp = [SELECT Name FROM Model_Definition__c WHERE Id = :ModelDefId LIMIT 1];
    try {
        return temp[0].Name;
    }
    catch(Exception e){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error: No objects could be found. Most likely, you no longer have a model selected. Please return to the model selection screen'));
    }
    return null;

 

 

but I still get a blank page displaying just the list out of bounds error. Does anyone know the proper way to override those error pages/messages?

 

Thanks!

Hi All,

 

I work with an ISV Partner who has a developer org where a managed package is updated / upgraded / tested and then uploaded "privately' to the exchange for a set of clients to install.

 

The orgs that install my package have the standard EE limits applied to them.

 

Herein lies the issue I have come across, whilst doing some development a new TAB was inadvertently added to the managed package and subsequently uploaded as a 'managed - released' package. It took the custom TABS within the managed package to 26.

 

This as you can see has caused HUGE implications across the current install base and for new clients. The package is constantly being updated / customised to suit clients needs and updates are continously being pushed however now that it has 26 TABS it will not install on any of the orgs as it reaches the 25 custom tab limit.

 

I REALLY NEED HELP BRAINSTORMING SOME POSSIBLE SOLUTIONS!!!

 

As I see it there are a range of possibilities and I look to any sf reps / partner ops / product managers subject matter experts out there to let me know what is feasible.

 

IDEAL SOLUTION - Since the tab that has been added is not installed on any clients org (it physically cannot be because of the limit on the install orgs, developer org doesn't have a tab limit) - I'm looking for an overall package admin or someone that can reference or edit the package I have created and manually remove the tab from it altogether. It can be deleted from the salesforce developer instance altogether I don't care it's not needed at all! Support tells me it cannot be deleted but someone out there must have access to it!!

Is there a way to 'rollback' to a previous package version that only had 25tabs in it's managed set>? And then be able to delete the 25th tab somehow completely from the developer org?

 

Other options include:

 

Going through the LMA process and getting the application security checked so that it's contents do not affect sf org limits. This is obviously primary concern right now however the whole process could take up to 2-3 weeks which is time we don't have! This problem needed to be sorted out YESTERDAY!

 

Upgrading provisions on future clients and current installbase so that orgs can install apps with more than 25 tabs. (i.e. increase tab limit)

 

I really need to know if the ideal solution is feasible here as that would be well... Ideal. But I'm interested to see if anyone has any other suggestions.

TIME IS A FACTOR. There are new clients coming on board this week and next not to mention the current install base that is catered for in package updates so this really needs to get sorted out.

 

As always any help is much appreciated. Thanks in advance for any reads of this post.

 

Patrick