• Brian Koblenz
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
This is going to sound stupid and crazy.  Sorry.

A year ago I developed a managed package for a 501c-3 I was working with.  The managed package is deployed on their system.
Fast forward a year, and there is a bug in some javascript that is associated with a button.  I cant edit the source because it is a managed package.

I went to log in using the username/password that I thought was used for the development, but I cannot log in.

So, the question is how can I get back to update the managed package when I dont know the developer edition that was used (and it has not been touched in a year) and I dont seem to be able to log in using the old credentials.  Alternatively, how can I make the managed package that is installed on the system editable to fix the bug.   Ugh.
 
I feel a bit stupid.  I have a pretty straightforward javascript custom button where I am trying to do a query and then iterate over the resulting set of objects.

My broken code is:
query_str = 'Select Id, ' + 
                'RecordType.Name, QB_Propagated__c ' +
                'FROM Opportunity WHERE ' +
                  'QB_Propagated__c=false AND ' + 
                  'RecordType.Name=\'Donation\' AND ' + 
                  'Id IN (\'' + idArray.toString().replace(/,/g, "','") + '\')';
alert(query_str);
ores = sforce.connection.query(query_str);
alert(ores);
alert('len: ' + ores.records.length);

The ores.records is defined and appears to be a list of entities that I want to iterate over (an alert(ores.records) gives me an object that starts {type:.....,} ), but my alert referencing the length of ores.records is undefined.

If I use the same query but do NOT include the AND ID IN ('sfid1','sfid2') in the query then the ores structure looks the same (to my eye!) but the code does work and I can refer to ores.records.length and get something meaningful.

In the "failing" version there is only one record that satisfies the condition.  If I extend my test so that two records satisfy my condition then I get the expected behavior.

Is it possible that I need two versions of code to deal with <=1 record returned from the query and >1 record?  I was hoping to just iterate over the length of the list.

-brian
 
I have been struggling for a few days trying to do something I would have expected to be reasonably straightforward.  I have created a custom button, visual force page, and apex class to support my goal.

I have a custom button on a related list and my overall goal is to clone every item in the related list and then reparent the clones to another master. My approach is to find all the elements in the related list by querying all the objects of the desired type who have the master id of the parent page that invoked the button.

My first query statement does seem to return the appropriate elements.  (btw, while the code below has hardcoded the parent_id, I wanted to extract the rightmost part of the url variable to get the parent_id, but I could not seem to use the right(), find() and len() functions feeding them the url variable.  If anyone can tell me how to do that it would also be appreciated.)

Here is the code:
var url = window.parent.location.href;
alert('url: ' + url);
var parent_id = 'a0fd000000EZGwt';

var query_str = "Select Id from HOMEtracker__Improvements_Adjustments__c where HOMEtracker__Service_File__r.Id = " + "'" + parent_id + "'";
alert('query: ' + query_str);

var allimp = sforce.connection.query(query_str);
alert('len: ' + allimp.records.length);
alert('recs: ' + allimp);

window.open('/apex/clonePlus?id=a0Wd0000008I89G&clone=1','_self');
window.open('/apex/clonePlus?id=a0Wd0000008IFyH&clone=1','_self');
window.parent.location.href = url;

var allimp2 = sforce.connection.query(query_str);
alert('newlen: ' + allimp2.records.length);
alert('recs2: ' + allimp2);

The purpose of the query is to get the set of ids that I need to clone and then I was going to loop over those ideas doing:
window.open(/apex/clonePlus.....) with the appropriate id.  My code above just hardcodes the attempt to perform two clones.

My next problem is that after the completion of my script I only have one clone and it is the one from the second window.open() call.  The clone code only clones one id at a time and a possible workaround would be to pass all of the ids, but I am really trying to understand why what I am doing here does not work.

Even though I know that one clone got created, (when the page is refreshed and I am done with my button), the second query statement which I expect to now find one additional item because of the clone still returns the same result as the original query.  Since I havent gotten around to any reparenting I was counting on the second query to give me back all of the entries (including the clones) so that I could then perform updates on the original entries and the clones.

Any help with my (at least) three different issues?

thanks
 
I am creating a custom button associated with a related list.  The purpose of the button is to take a set of items in the related list associated with parent object P, copy them and associate the copies with parent object P1.  I would like the copies to have all the data of the original object, but have a new parent.  Furthermore, I would like this button to continue to work without modification if new fields are added to the object.

I (naively) assumed that the SObject constructor would take an Id for an object and create a copy.  I also understand through a /id/e?clone=1 I could close a list of objects, but I assume they would be tied to object P which is undesirable.  In terms of created dates etc I dont care if the field is copied or set anew.

I have the rough button code below.   The area surrounded by **clone start** and **clone end** is where I am struggling.

On a more minor note, is there a way that my boolean check Propagated__c can be directly tested rather than comparing against the string "false" which must be coming from the query?

thanks
-brian

var idArray = {!GETRECORDIDS($ObjectType.HOMEtracker__Improvements_Adjustments__c)};
if (idArray.length == 0) { 
   alert('Please select at least one record'); 
}
else if (false) {
   alert('Improvement->Service File->Buyer field must be filled in prior to propagation.');
}
else { 
   var updated_records = [];
   var new_records = [];
   var num_updated = 0;
   var improvs = sforce.connection.retrieve(
            'Id,Propagated__c,Closure_Date__c,Current_Depreciation__c',
            'HOMEtracker__Improvements_Adjustments__c', idArray);
   for(var i=0; i<idArray.length; i++) {
      if (improvs[i].Propagated__c == 'false' &&
               improvs[i].Closure_Date__c == null) {
         num_updated++;
**clone start** 
         var i_copy = clone the object with id==idArray[i]
         i_copy.Parent__c = P1;  (this would be the reparenting step.)
         new_records.push(i_copy);
**clone end**

         var improv = new sforce.SObject(
                                "HOMEtracker__Improvements_Adjustments__c"); 
         improv.id = idArray[i]; 
         improv.Propagated__c = true; 
         updated_records.push(improv);
      } 
   } 
   result = sforce.connection.update(updated_records);
   result = sforce.connection.create(new_records);
   alert('Number of copied records: '+num_updated);
   window.location.reload(); 
}
I feel a bit stupid.  I have a pretty straightforward javascript custom button where I am trying to do a query and then iterate over the resulting set of objects.

My broken code is:
query_str = 'Select Id, ' + 
                'RecordType.Name, QB_Propagated__c ' +
                'FROM Opportunity WHERE ' +
                  'QB_Propagated__c=false AND ' + 
                  'RecordType.Name=\'Donation\' AND ' + 
                  'Id IN (\'' + idArray.toString().replace(/,/g, "','") + '\')';
alert(query_str);
ores = sforce.connection.query(query_str);
alert(ores);
alert('len: ' + ores.records.length);

The ores.records is defined and appears to be a list of entities that I want to iterate over (an alert(ores.records) gives me an object that starts {type:.....,} ), but my alert referencing the length of ores.records is undefined.

If I use the same query but do NOT include the AND ID IN ('sfid1','sfid2') in the query then the ores structure looks the same (to my eye!) but the code does work and I can refer to ores.records.length and get something meaningful.

In the "failing" version there is only one record that satisfies the condition.  If I extend my test so that two records satisfy my condition then I get the expected behavior.

Is it possible that I need two versions of code to deal with <=1 record returned from the query and >1 record?  I was hoping to just iterate over the length of the list.

-brian
 
I have 2 custom objects, object1(Parent) and object2(Child), i want a clone button on object1 so everytime i clone then it needs to carry over records from object2. I created this button but it doesn't carry over the related records, i know i haven't added any logic to carry the records yet but if anyone can help me here i would really appreciate it

https://na2.salesforce.com/{!object1__c.Id}/e?clone=1&retURL=%{!object1.Id}
I am creating a custom button associated with a related list.  The purpose of the button is to take a set of items in the related list associated with parent object P, copy them and associate the copies with parent object P1.  I would like the copies to have all the data of the original object, but have a new parent.  Furthermore, I would like this button to continue to work without modification if new fields are added to the object.

I (naively) assumed that the SObject constructor would take an Id for an object and create a copy.  I also understand through a /id/e?clone=1 I could close a list of objects, but I assume they would be tied to object P which is undesirable.  In terms of created dates etc I dont care if the field is copied or set anew.

I have the rough button code below.   The area surrounded by **clone start** and **clone end** is where I am struggling.

On a more minor note, is there a way that my boolean check Propagated__c can be directly tested rather than comparing against the string "false" which must be coming from the query?

thanks
-brian

var idArray = {!GETRECORDIDS($ObjectType.HOMEtracker__Improvements_Adjustments__c)};
if (idArray.length == 0) { 
   alert('Please select at least one record'); 
}
else if (false) {
   alert('Improvement->Service File->Buyer field must be filled in prior to propagation.');
}
else { 
   var updated_records = [];
   var new_records = [];
   var num_updated = 0;
   var improvs = sforce.connection.retrieve(
            'Id,Propagated__c,Closure_Date__c,Current_Depreciation__c',
            'HOMEtracker__Improvements_Adjustments__c', idArray);
   for(var i=0; i<idArray.length; i++) {
      if (improvs[i].Propagated__c == 'false' &&
               improvs[i].Closure_Date__c == null) {
         num_updated++;
**clone start** 
         var i_copy = clone the object with id==idArray[i]
         i_copy.Parent__c = P1;  (this would be the reparenting step.)
         new_records.push(i_copy);
**clone end**

         var improv = new sforce.SObject(
                                "HOMEtracker__Improvements_Adjustments__c"); 
         improv.id = idArray[i]; 
         improv.Propagated__c = true; 
         updated_records.push(improv);
      } 
   } 
   result = sforce.connection.update(updated_records);
   result = sforce.connection.create(new_records);
   alert('Number of copied records: '+num_updated);
   window.location.reload(); 
}