• Stefanos.Thomaidis
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 10
    Replies

The following code worked last week!

It clones the first record of a related object.  I keep it on a button.

Has anything chenged in Salesforce over the weekend?

The code:

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

var a = {!Location__c.Name}

var result  = sforce.connection.query("SELECT SessionIDs__c FROM Promo_Material_Snapshot__c"+  
" WHERE Location_ID__c = '"+ a +"'  limit 1")

// var result  = sforce.connection.query("SELECT SessionIDs__c FROM Promo_Material_Snapshot__c limit 1")

var records = result.getArray("records")
var IdsToClone = String(records[0]).substring(60, 75)
window.open("/"+IdsToClone +"/e?clone=1&retURL=/"+IdsToClone )

 

Now it gives the following error:

 

faultcode: MALFOREMED QUERY..

...

no viable alternative at character...

 

Last Week it Worked Fine!

 

Any ideas / Suggestions?

All the best,

Stefanos

Dear all,

 

I have created the following test class to test a trigger that works.  The trigger changes the value on a dependend object's picklist according to the choice of the parent object.

The test reaches only 55%.

It needs to reach 75% coverage.

Below is the test code and way beyod the trigger.

Any suggestions are more than welcome!

 

Test Code:

 

@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);

List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
Location.add(b);
insert Location;
}

test.startTest();
insert accounts;
test.stopTest();
}
}

 

Trigger:

trigger updateactive on Account (after update, after insert){
Location__c[] StatusToUpdate = new Location__c[]{};
for(Account  c : trigger.new ){
for(Location__c cp: [ 
select id,name,Status__c from Location__c  
where Associate__c =:c.id]){
if ( c.Status__c == 'Under Deactivation'){
cp.Status__c = 'Under Deactivation';
}
StatusToUpdate.add(cp);
}
}
if(StatusToUpdate.size()>0) 
update StatusToUpdate;
}

Greetings,

 

I am trying to figure out the correct code for a picklist item on a related object to get the value of a picklist item from its parent custom object.

When the value changes and gets a specific string, then I have to have a change on the corresponding picklist in the related object.

 

Thanks for passing by,

2 issues.

 

1.  var a never gets the actual salesforce 15 digit id for the custom object "Location__c". How do I get this value?

2. When I build the query I ge the message "unexpected token".  How do I use a variable like "a" in a query statement such as below?:

 

 

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

 

var a = {!Location__c.Id}

var result = sforce.connection.query("SELECT Id FROM Promo_Material_Snapshot__c"+
" WHERE Location__c = a limit 1")

 

var records = result.getArray("records")

var IdsToClone = String(records[0]).substring(40, 55)

 

window.open("/"+IdsToClone +"/e?clone=1&retURL=/"+IdsToClone )

Dear all,

 

I have created the following test class to test a trigger that works.  The trigger changes the value on a dependend object's picklist according to the choice of the parent object.

The test reaches only 55%.

It needs to reach 75% coverage.

Below is the test code and way beyod the trigger.

Any suggestions are more than welcome!

 

Test Code:

 

@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);

List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
Location.add(b);
insert Location;
}

test.startTest();
insert accounts;
test.stopTest();
}
}

 

Trigger:

trigger updateactive on Account (after update, after insert){
Location__c[] StatusToUpdate = new Location__c[]{};
for(Account  c : trigger.new ){
for(Location__c cp: [ 
select id,name,Status__c from Location__c  
where Associate__c =:c.id]){
if ( c.Status__c == 'Under Deactivation'){
cp.Status__c = 'Under Deactivation';
}
StatusToUpdate.add(cp);
}
}
if(StatusToUpdate.size()>0) 
update StatusToUpdate;
}

2 issues.

 

1.  var a never gets the actual salesforce 15 digit id for the custom object "Location__c". How do I get this value?

2. When I build the query I ge the message "unexpected token".  How do I use a variable like "a" in a query statement such as below?:

 

 

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

 

var a = {!Location__c.Id}

var result = sforce.connection.query("SELECT Id FROM Promo_Material_Snapshot__c"+
" WHERE Location__c = a limit 1")

 

var records = result.getArray("records")

var IdsToClone = String(records[0]).substring(40, 55)

 

window.open("/"+IdsToClone +"/e?clone=1&retURL=/"+IdsToClone )