• alexb
  • NEWBIE
  • 125 Points
  • Member since 2011

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 37
    Replies

I run my test case (see below) and it only covers it 60%.  when I read the detailed output it doesn't look like the trigger is working?  thanks for your help!  After the test case I listed the debug log....

 

Also why do my System.assertEquals statement return : System.assertEquals(ANY, ANY) - instead of the value???

 

Thanks for your help!

Karen

 

@isTest
private class ConvertOppLIQtyTest{
    static testMethod void testOppLIQty(){
    
 
    
    //Setup the Account record
    Account a = new Account(Name = 'Test Account');
    a.Type = 'Customer';
    insert a;
    
    // Verify that the initial state is as expected
    a = [SELECT Name, Type
        FROM Account
        Where Id = :a.Id];
    System.assertEquals ('Customer', a.Type);
    
    // setup the Opportunity record
    
    String opportunityName = 'Test Opportunity';
    Opportunity o = new Opportunity(AccountId=a.Id, name=opportunityName, StageName='4 - Closed Won', CloseDate = Date.today(),PO_Number__c='999', Order_ID__c='999', opp_ship_to__c='017' );
                                    
    
    insert o;
    
    opportunity opp = [select name from opportunity where Id = :o.Id];
     System.assertEquals (opportunityname, opp.name);

//     ----------------------------------------

     // set up product2 and Verify that the results are as expected.
        Product2 p2 = new Product2(Name='AMS300',isActive=true);
        insert p2;
        Product2 p2ex = [SELECT Name FROM Product2 WHERE Id = :p2.Id];
        System.assertEquals('AMS300', p2ex.Name);
        
// set up PricebookEntry and Verify that the results are as expected.
        PricebookEntry pbe = new PricebookEntry(Pricebook2Id='01s700000002a7TAAQ', Product2Id=p2.Id, UnitPrice=99, isActive=true);
        insert pbe;
        PricebookEntry pbeex = [SELECT Pricebook2Id FROM PricebookEntry WHERE Id = :pbe.Id ];
 //       System.assertEquals(standardPriceBookId, pbeex.Pricebook2Id);
        
// set up OpportunityLineItem and Verify that the results are as expected.
        OpportunityLineItem oli = new OpportunityLineItem(PriceBookEntryId=pbe.Id, OpportunityId=o.Id, Quantity=1, TotalPrice=99);
       
 
 //------------------------
        
            // set up product2 and Verify that the results are as expected.
        Product2 p2a = new Product2(Name='AMS305-10PK',isActive=true);
        insert p2a;
        Product2 p2exa = [SELECT Name FROM Product2 WHERE Id = :p2a.Id];
        System.assertEquals('AMS305-10PK', p2exa.Name);
        
// set up PricebookEntry and Verify that the results are as expected.
        PricebookEntry pbea = new PricebookEntry(Pricebook2Id='01s700000002a7TAAQ', Product2Id=p2a.Id, UnitPrice=99, isActive=true);
        insert pbea;
        PricebookEntry pbeexa = [SELECT Pricebook2Id FROM PricebookEntry WHERE Id = :pbea.Id ];
//        System.assertEquals(standardPriceBookId, pbeexa.Pricebook2Id);
        
// set up OpportunityLineItem and Verify that the results are as expected.
        OpportunityLineItem olia = new OpportunityLineItem(PriceBookEntryId=pbea.Id, OpportunityId=o.Id, Quantity=1, TotalPrice=99);
       
           
    Test.startTest();
          insert oli;
          insert olia;
    Test.stopTest();


    
 
    }
}

 

---------------------------------DEBUG LOG----------------------------------------------------------------

21.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST
09:52:36.086|EXECUTION_STARTED
09:52:36.086|CODE_UNIT_STARTED|[EXTERNAL]|01pQ00000001FRX|ConvertOppLIQtyTest.testOppLIQty
09:52:36.086|METHOD_ENTRY|[2]|01pQ00000001FRX|ConvertOppLIQtyTest.ConvertOppLIQtyTest()
09:52:36.086|METHOD_EXIT|[2]|ConvertOppLIQtyTest
09:52:36.086|DML_BEGIN|[10]|Op:Insert|Type:Account|Rows:1
09:52:36.213|DML_END|[10]
09:52:36.213|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|SELECT Name, Type
FROM Account
Where Id = :a.Id
09:52:36.219|SOQL_EXECUTE_END|[13]|Rows:1
09:52:36.219|METHOD_ENTRY|[16]|System.assertEquals(ANY, ANY)
09:52:36.219|METHOD_EXIT|[16]|System.assertEquals(ANY, ANY)
09:52:36.219|METHOD_ENTRY|[21]|Date.today()
09:52:36.220|METHOD_EXIT|[21]|Date.today()
09:52:36.220|DML_BEGIN|[24]|Op:Insert|Type:Opportunity|Rows:1
09:52:36.356|DML_END|[24]
09:52:36.356|SOQL_EXECUTE_BEGIN|[26]|Aggregations:0|select name from opportunity where Id = :o.Id
09:52:36.361|SOQL_EXECUTE_END|[26]|Rows:1
09:52:36.361|METHOD_ENTRY|[27]|System.assertEquals(ANY, ANY)
09:52:36.362|METHOD_EXIT|[27]|System.assertEquals(ANY, ANY)
09:52:36.362|DML_BEGIN|[33]|Op:Insert|Type:Product2|Rows:1
09:52:36.419|DML_END|[33]
09:52:36.419|SOQL_EXECUTE_BEGIN|[34]|Aggregations:0|SELECT Name FROM Product2 WHERE Id = :p2.Id
09:52:36.424|SOQL_EXECUTE_END|[34]|Rows:1
09:52:36.424|METHOD_ENTRY|[35]|System.assertEquals(ANY, ANY)
09:52:36.424|METHOD_EXIT|[35]|System.assertEquals(ANY, ANY)
09:52:36.424|DML_BEGIN|[39]|Op:Insert|Type:PricebookEntry|Rows:1
09:52:36.476|DML_END|[39]
09:52:36.476|SOQL_EXECUTE_BEGIN|[40]|Aggregations:0|SELECT Pricebook2Id FROM PricebookEntry WHERE Id = :pbe.Id 
09:52:36.479|SOQL_EXECUTE_END|[40]|Rows:1
09:52:36.480|DML_BEGIN|[51]|Op:Insert|Type:Product2|Rows:1
09:52:36.492|DML_END|[51]
09:52:36.492|SOQL_EXECUTE_BEGIN|[52]|Aggregations:0|SELECT Name FROM Product2 WHERE Id = :p2a.Id
09:52:36.496|SOQL_EXECUTE_END|[52]|Rows:1
09:52:36.496|METHOD_ENTRY|[53]|System.assertEquals(ANY, ANY)
09:52:36.496|METHOD_EXIT|[53]|System.assertEquals(ANY, ANY)
09:52:36.496|DML_BEGIN|[57]|Op:Insert|Type:PricebookEntry|Rows:1
09:52:36.504|DML_END|[57]
09:52:36.504|SOQL_EXECUTE_BEGIN|[58]|Aggregations:0|SELECT Pricebook2Id FROM PricebookEntry WHERE Id = :pbea.Id 
09:52:36.507|SOQL_EXECUTE_END|[58]|Rows:1
09:52:36.507|METHOD_ENTRY|[1]|Test.Test()
09:52:36.507|METHOD_EXIT|[1]|Test
09:52:36.507|METHOD_ENTRY|[65]|system.Test.startTest()
09:52:36.508|METHOD_EXIT|[65]|system.Test.startTest()
09:52:36.508|DML_BEGIN|[66]|Op:Insert|Type:OpportunityLineItem|Rows:1
09:52:36.516|CODE_UNIT_STARTED|[EXTERNAL]|01qQ00000000KbX|convertOppLIqty on OpportunityLineItem trigger event BeforeInsert for [new]
09:52:36.516|METHOD_ENTRY|[7]|System.debug(ANY)
09:52:36.516|USER_DEBUG|[7]|DEBUG|INSIDE OPP FOR LOOP!!!
09:52:36.516|METHOD_EXIT|[7]|System.debug(ANY)
09:52:36.516|METHOD_ENTRY|[11]|System.debug(ANY)
09:52:36.516|USER_DEBUG|[11]|DEBUG|01uQ0000004gObvIAE
09:52:36.516|METHOD_EXIT|[11]|System.debug(ANY)
09:52:36.516|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select Product2Id from PricebookEntry where id = :insertedlineitem.PricebookEntryId
09:52:36.519|SOQL_EXECUTE_END|[12]|Rows:1
09:52:36.519|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select productcode from product2 where id = :PBE.product2id
09:52:36.522|SOQL_EXECUTE_END|[13]|Rows:1
09:52:36.522|METHOD_ENTRY|[15]|System.debug(ANY)
09:52:36.522|USER_DEBUG|[15]|DEBUG|PROD CODE null
09:52:36.522|METHOD_EXIT|[15]|System.debug(ANY)
09:52:36.523|METHOD_ENTRY|[31]|System.debug(ANY)
09:52:36.523|USER_DEBUG|[31]|DEBUG|77
09:52:36.523|METHOD_EXIT|[31]|System.debug(ANY)
09:52:36.817|CUMULATIVE_LIMIT_USAGE
09:52:36.817|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 6 out of 100
Number of query rows: 6 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 7 out of 150
Number of DML rows: 7 out of 10000
Number of script statements: 28 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.817|TESTING_LIMITS
09:52:36.817|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 2 out of 100
Number of query rows: 2 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of script statements: 8 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.817|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
09:52:36.817|CUMULATIVE_LIMIT_USAGE_END

09:52:36.523|CODE_UNIT_FINISHED|convertOppLIqty on OpportunityLineItem trigger event BeforeInsert for [new]
09:52:36.605|DML_END|[66]
09:52:36.605|DML_BEGIN|[67]|Op:Insert|Type:OpportunityLineItem|Rows:1
09:52:36.610|CODE_UNIT_STARTED|[EXTERNAL]|01qQ00000000KbX|convertOppLIqty on OpportunityLineItem trigger event BeforeInsert for [new]
09:52:36.610|METHOD_ENTRY|[7]|System.debug(ANY)
09:52:36.610|USER_DEBUG|[7]|DEBUG|INSIDE OPP FOR LOOP!!!
09:52:36.610|METHOD_EXIT|[7]|System.debug(ANY)
09:52:36.611|METHOD_ENTRY|[11]|System.debug(ANY)
09:52:36.611|USER_DEBUG|[11]|DEBUG|01uQ0000004gObwIAE
09:52:36.611|METHOD_EXIT|[11]|System.debug(ANY)
09:52:36.611|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|select Product2Id from PricebookEntry where id = :insertedlineitem.PricebookEntryId
09:52:36.613|SOQL_EXECUTE_END|[12]|Rows:1
09:52:36.613|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|select productcode from product2 where id = :PBE.product2id
09:52:36.618|SOQL_EXECUTE_END|[13]|Rows:1
09:52:36.618|METHOD_ENTRY|[15]|System.debug(ANY)
09:52:36.618|USER_DEBUG|[15]|DEBUG|PROD CODE null
09:52:36.618|METHOD_EXIT|[15]|System.debug(ANY)
09:52:36.618|METHOD_ENTRY|[31]|System.debug(ANY)
09:52:36.618|USER_DEBUG|[31]|DEBUG|77
09:52:36.618|METHOD_EXIT|[31]|System.debug(ANY)
09:52:36.912|CUMULATIVE_LIMIT_USAGE
09:52:36.912|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 6 out of 100
Number of query rows: 6 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 7 out of 150
Number of DML rows: 7 out of 10000
Number of script statements: 28 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.912|TESTING_LIMITS
09:52:36.912|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 4 out of 100
Number of query rows: 4 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of script statements: 17 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.912|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
09:52:36.912|CUMULATIVE_LIMIT_USAGE_END

09:52:36.619|CODE_UNIT_FINISHED|convertOppLIqty on OpportunityLineItem trigger event BeforeInsert for [new]
09:52:36.665|DML_END|[67]
09:52:36.665|METHOD_ENTRY|[68]|system.Test.stopTest()
09:52:36.665|METHOD_EXIT|[68]|system.Test.stopTest()
09:52:36.959|CUMULATIVE_LIMIT_USAGE
09:52:36.959|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 6 out of 100
Number of query rows: 6 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 7 out of 150
Number of DML rows: 7 out of 10000
Number of script statements: 28 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.959|TESTING_LIMITS
09:52:36.959|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 4 out of 100
Number of query rows: 4 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of script statements: 18 out of 200000
Maximum heap size: 0 out of 3000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

09:52:36.959|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
09:52:36.959|CUMULATIVE_LIMIT_USAGE_END

09:52:36.665|CODE_UNIT_FINISHED|ConvertOppLIQtyTest.testOppLIQty
09:52:36.665|EXECUTION_FINISHED
09:52:38.311|CUMULATIVE_PROFILING_BEGIN
09:52:38.311|CUMULATIVE_PROFILING|No profiling information for SOQL operations
09:52:38.311|CUMULATIVE_PROFILING|No profiling information for SOSL operations
09:52:38.311|CUMULATIVE_PROFILING|No profiling information for DML operations
09:52:38.311|CUMULATIVE_PROFILING|No profiling information for method invocations
09:52:38.311|CUMULATIVE_PROFILING_END

In Apex REST, regarding returning values, what's the difference between

     [return leadList;]

and

     [return JSON.serialize(leadList);]?

 

I'm seeing they serialize differently.

The former returns:

     [{City"Fargo", FirstName"Test", LastName"McTesty", State"ND"}]

The latter returns:

     [{"attributes":{"type":"Lead"},"State":"ND","FirstName":"Test","LastName":"McTesty","City":"Fargo"}]

 

The docs say: "An Apex method with a non-void return type will have the return value serialized into RestResponse.responseBody.", but what does this mean? What method of serialization is used?

 

So, it seems that if we use the JSON serializer, we'll get some extra information beyond just the fields I want to send. Why does the JSON serializer add the extra 'attributes' property? It seems this extra complexity means that we shouldn't use the JSON serializer for REST responses, sound right? My Javascript framework seems to be choking on the latter.

 

Or a better question: What serialization technique is used by the former, and why is it different from the latter?

 

*edit*

After testing a bit more with custom objects, not sObjects, it seems that the former method will resolve easily to JS Object by a JS client, while the latter method will resolve to a JSON string. 

  • April 05, 2012
  • Like
  • 0

I want to make a report on Opportunity, Estimates (custom objects), and a detail object on Estimates.

 

First step I did was make a Custom Report Type that related Opportunity, Estimate, and the estimate detail objects. When I made a report based on this CRT, however, I would receive zero records returned. I made a new CRT, this time with just Opportunity and no other objects, but I get the same results.

 

Covering my bases...

- When I run other standard Opportunity reports, I can view the records just fine.

- I checked date and field filters for the report, and there are none.

 

Anything that I'm overlooking? Some permission I'm missing?

 

Thanks for your help in advance! I've been wrestling with this one for a few days, trying to come up with ideas.

 

Edit: I tried the same report with the same CRT in the org's sandbox, and it DOES return Opportuny records in the sandbox (not full-date).

  • December 23, 2011
  • Like
  • 0

I'm want to write some JS in a custom button to update the status field of the current object. I found some example code that seems to do what I want, but I'm getting an error when performing the update.

 

http://pastebin.com/MQdFdFde

 

The error I'm getting is: Refused to set unsafe header "User-Agent"

I get this error when I try to update SF with result = sforce.connection.update(updateRecords);

 

Any tips?

  • July 25, 2011
  • Like
  • 0

I am trying to write some code to see what cron jobs currently exist in my SF org, but I'm having troubles.

 

Here's what I am trying to do in a trigger I have on a custom object.

 

 

CronTrigger existingCronJob = [SELECT Id, CronExpression FROM CronTrigger WHERE Id = :configObject.Scheduled_Email_Job_Id__c LIMIT 1];
In the Force.com IDE in Eclipse, it gives me an error "Save error: sObject type 'CronTrigger' is not supported."

 

 

 

Look here, do page search for 'CronTrigger'. It explicitly says that  "Q: Is it possible to query the last time a scheduled batch process completed? A: Yes, you can query the CronTrigger table."

http://wiki.developerforce.com/index.php/Tech_Talk:_Whats_New_in_Apex_Code_FAQ

 

So what gives? Any answers out there?

 

Thanks!

-Alex

  • March 10, 2011
  • Like
  • 0

I've scoured the net and SF boards, but I could not find a single example of how to remove Chatter followers from an object. I'm pretty sure I did it right by just removing the correct EntityRelationship record, but the test method is failing. Either I wrote the removeAllFollowers method wrong, or I wrote the test wrong. Can you take a look and tell me if you see anything obvious? Thanks! 

 

Goal: When a Project__c is closed, remove all Chatter followers.

 

Problem: When I run my getFollowers() method two different times on the same Project__c object, I get two different records. Driving me crazy.

 

 

public static Boolean removeAllFollowers(Set<Id> objectToUnfollowIdSet) {
    
     List<EntitySubscription> subscriptionsToDeleteList =
     [SELECT e.Id, e.parentId, e.subscriberId
     FROM EntitySubscription e
     WHERE e.parentId IN :objectToUnfollowIdSet];
    
     try {
     delete subscriptionsToDeleteList;
     } catch (System.Exception e) {
     throw e;
     return false;
     }
    
     return true;
    }
public static Map<Id, Set<Id>> getFollowers(List<Id> objectIdList) {
    
     Map<Id, Set<Id>> objectToFollowerMap = new Map<Id, Set<Id>>();
     Set<Id> followerIdSet = new Set<Id>();
     List<EntitySubscription> subscriberList = [SELECT e.ParentId, e.SubscriberId 
     FROM EntitySubscription e
     WHERE e.ParentId IN :objectIdList];
     for (Id objectId : objectIdList) {
     followerIdSet.clear();
     for (EntitySubscription subscriber : subscriberList) {
     if (subscriber.parentId == objectId) {
     followerIdSet.add(subscriber.subscriberId);
     }
     }
     System.debug('objectId: ' + objectId + ' followerIdSet: ' + followerIdSet);
 objectToFollowerMap.put(objectId, followerIdSet);    
     }
     return objectToFollowerMap;
    }
static testMethod void testProjectCloses_HasChatterFollowers() {
     // Create test data
     User user1 = TestHelper.createUser('first', 'last', 'email@email.com', TestHelper.getSysAdminProfile().Id);
     Project__c project1 = TestHelper.createProject('project1', user1.Id);
     User user2 = TestHelper.createUser('bob', 'follower', 'email2@email.com', TestHelper.getSysAdminProfile().Id);
     EntitySubscription subscription = TestHelper.createChatterFollower(project1.Id, user2.Id);
     System.debug('SUBSCRIPTION: ' + subscription);
     // Ensure data is as expected
     Map<Id, Set<Id>> followersMap = ChatterHelper.getFollowers(new List<Id>{project1.Id});
 // This debug gives an ID of X
     System.debug('FOLLOWERSMAP: ' + followersMap);
     System.assertEquals(1, followersMap.size());
    
     // Invoke functionality
     System.Test.startTest();
     project1.Status__c = 'Closed';
     update project1;
     System.Test.stopTest();
    
     // Check results
     project1 = [SELECT p.Id, p.Status__c FROM Project__c p WHERE p.Id = :project1.Id];
     followersMap = ChatterHelper.getFollowers(new List<Id>{project1.Id});
 // This debug gives an ID of Y
     System.debug('FOLLOWERSMAP: ' + followersMap);
 // Failing here on this assert
     System.assertEquals(0, followersMap.size());
    }

 

  • January 13, 2011
  • Like
  • 0

I noticed this issue while writing an Apex test case for some chatter related functionality. For sake of this post, I am just posting the simplified test case. Here is the code

 

public static testmethod void testFeeds() {
  Test.startTest();
    // Create a Test Account
    Account acc = new Account(Name = 'Demo Account');
    insert acc;
    
    // Create FeedItem using this Account as a Parent Record
    FeedItem fp = new FeedItem();
    fp.Body = 'Testing via Apex';
    fp.parentId = acc.id;
    insert fp;
    
    // Query AccountFeed back to verify if the post was created correctly
    AccountFeed[] accFeed = [Select Id, Body From AccountFeed Where ParentId =:acc.Id];
    // should be 1 record in the feed for this accountid
    System.assertEquals(1, accFeed.size());
  Test.stopTest();
}

 

This test case fails, because there are no rows in AccountFeed for the given “parentId”. This happens only if Apex class API version is “24”, but the same tests passes if the API version is lowered, for ex. “23”.

Seems something is broken in Apex Test fixture.

In Apex REST, regarding returning values, what's the difference between

     [return leadList;]

and

     [return JSON.serialize(leadList);]?

 

I'm seeing they serialize differently.

The former returns:

     [{City"Fargo", FirstName"Test", LastName"McTesty", State"ND"}]

The latter returns:

     [{"attributes":{"type":"Lead"},"State":"ND","FirstName":"Test","LastName":"McTesty","City":"Fargo"}]

 

The docs say: "An Apex method with a non-void return type will have the return value serialized into RestResponse.responseBody.", but what does this mean? What method of serialization is used?

 

So, it seems that if we use the JSON serializer, we'll get some extra information beyond just the fields I want to send. Why does the JSON serializer add the extra 'attributes' property? It seems this extra complexity means that we shouldn't use the JSON serializer for REST responses, sound right? My Javascript framework seems to be choking on the latter.

 

Or a better question: What serialization technique is used by the former, and why is it different from the latter?

 

*edit*

After testing a bit more with custom objects, not sObjects, it seems that the former method will resolve easily to JS Object by a JS client, while the latter method will resolve to a JSON string. 

  • April 05, 2012
  • Like
  • 0

I'm interested in createing an email alert that informs me when the number of messages (a custom object) assined to a queue surpasses a set number. Normally, I set up email alerts with workflow rules as it is easy to add an email action but I think this case is a bit more coplicated then the rather simple workflow rules will permit. Any thoughts? 

I want to make a report on Opportunity, Estimates (custom objects), and a detail object on Estimates.

 

First step I did was make a Custom Report Type that related Opportunity, Estimate, and the estimate detail objects. When I made a report based on this CRT, however, I would receive zero records returned. I made a new CRT, this time with just Opportunity and no other objects, but I get the same results.

 

Covering my bases...

- When I run other standard Opportunity reports, I can view the records just fine.

- I checked date and field filters for the report, and there are none.

 

Anything that I'm overlooking? Some permission I'm missing?

 

Thanks for your help in advance! I've been wrestling with this one for a few days, trying to come up with ideas.

 

Edit: I tried the same report with the same CRT in the org's sandbox, and it DOES return Opportuny records in the sandbox (not full-date).

  • December 23, 2011
  • Like
  • 0

Hi all,

 

I'm using the following case statement to within a VF page to adjust some language.  Within one of the options is an apostrophe and I'm having difficulty escaping it.

 

Here's what I have:

{!case(MyOBJ__c.MyField__c,
'Any time',' at any time.',
'Based on Employer policy',' based on your employer\'s policy.',
'MERGE ERROR')}

 Doing this results in "based on your employer\'s policy" being displayed on the page.

 

Using \\'s results in a nasty looking Error: EL Expression Unbalanced: ...

 

And for grins, using \\\'s results in "based on your employer\\'s policy"

I'm want to write some JS in a custom button to update the status field of the current object. I found some example code that seems to do what I want, but I'm getting an error when performing the update.

 

http://pastebin.com/MQdFdFde

 

The error I'm getting is: Refused to set unsafe header "User-Agent"

I get this error when I try to update SF with result = sforce.connection.update(updateRecords);

 

Any tips?

  • July 25, 2011
  • Like
  • 0

Hi,

 

I have a exception log class which records all exceptions in a exception log object.  I am trying to write test case for it. I have covered most of the class but I am not able to cover the block of code is catch box. Can anyone help em with a test code for the code in catch block?

 

public class ExceptionLogClass {
    public static void insertErrorLog(String errorIn, String severityIn, String errorSourceIn, String causedByUserIn)
    {
        Exception_Log__c eL = new Exception_Log__c();
        try{
            eL.Error__c = errorIn;
            eL.Severity__c = severityIn;
            eL.Error_Source__c = errorSourceIn;
            eL.Caused_by_User__c = causedByUserIn;
            insert eL;
        }
        catch(Exception e){
            Apexpages.Message msg = new Apexpages.Message(Apexpages.Severity.Fatal, e.getMessage());
            Apexpages.addMessage(msg);            
        }
    }
    
}

 I am not sure how I should write test case code for the code in catch box. I get only 72% coverage becasue of it.

 

Here is the code which can cause the exception. Severity can only be "Fatal", "Error", "Info", "Warning"  and "Confirm"

 

ExceptionLogClass.insertErrorLog('Error Test', 'Fat', 'Test ExceptionLog Class', Userinfo.getName());

 Thank you.

Does anyone know how to change the Reports OwnerId through code?  I get the error, Field is not writeable: Report.OwnerId.

 

Basically the reason for this is that i'm doing a query to return Reports and if they are returned I want to place them in a specific folder.

 

List<Report> temp = [SELECT name, LastRunDate FROM Report WHERE LastRunDate >=: (System.today() - 90)];

for (Report curr: temp)     

    curr.OwnerId = myfolder.id;

upsert temp;

I'm trying to collect common fields from a webform in a cookie so that I can auto-fill them for my users when they visit our webform multiple times. For example if they've visited the page and filled out the form in the last 3 years I want it to auto-fill the First Name, Last Name, Email, Phone, and Extension fields for them. 

 

This page was previously written with Javascript, and I'd like to translate it into an apex controller instead.

 

My issue lies in that the values for cookies can only be set in constructors, I don't now how to collect the data after the page has been loaded and the constructor called.

 

I received some vague advice from a coworker about using page references but it didn't help much.

 

Any help would be much appreciated!

Hey all,

 

I have developed some code that will create a customer portal user using apex. It basically follows the principles in this article. It works correctly, and the user created recieves an email with their login details (username and password).

 

My expectation would have been that when the user first logins successfully with these details, they would be forced to change the password to something different. But my testing does not reflect this expectation.

 

Can anyone confirm that if the behaviour I'm seeing is correct or not? Should the user have to change password on first login?

 

Thanks 

Hi Guys,

 

I'm working through some app development and I've hit a snag. I have some jQuery code which is called using the .ready() function in jQuery. This all works fine until the point I have a ReRender and the DOM is redrawn my code no longer works.

 

Here's my page:

 

 

<apex:page standardController="Handover__c" extensions="HandoverExtension" sidebar="false">
	<apex:includeScript value="{!URLFOR($Resource.JQueryUI, 'jQueryUI/js/jquery-1.5.1.min.js')}"  />
	<script>
		$j = jQuery.noConflict();
		$j(document).ready(function(){
			$j("td.ItemTextCol").find("a").each(function(){
				if($j(this).text().length > 40){
					$j(this).attr("title", $j(this).attr("href"));
					$j(this).text("Long URL Replaced");
				}
			});
		});
	</script>
	<apex:form >
<apex:outputpanel id="ItemLists">
	<apex:pageblock title="Handover Items" mode="detail">
            <apex:actionStatus id="updateStatus">
       		<apex:facet name="start">
       			<apex:outputPanel >
       				<apex:image url="/img/loading.gif"/>
       				<apex:outputtext value=" Working..."/>
       			</apex:outputPanel>
       		</apex:facet>
   		</apex:actionStatus>
		<apex:pageblocktable value="{!Items.handoveritems}" var="i">
				<apex:commandLink action="{!i.activate_deactivate}" rerender="ItemLists" rendered="{!NOT(Items.hasActivate)}" status="updateStatus"> 
					<apex:image url="{!URLFOR($Resource.handover_images, 'HandoverImages/Delete.png')}" alt="Deactivate this Handover Item" title="Deactivate this Handover Item"/>
				</apex:commandLink>
			</apex:column>
			<apex:column Headervalue="Summary" styleClass="ItemTextCol">
				<apex:outputField value="{!i.item.Summary__c}" styleClass="ItemText"/>
			</apex:column>
			<apex:column headerValue="Current Status" >
				<apex:outputField value="{!i.item.Current_Status__c}" />
		</apex:pageblocktable> 
	</apex:pageblock>
	</apex:outputpanel>
</apex:form> 
</apex:page>

Now this all works until the point where I click on the CommandLink and there is a partial page refresh.  

 

Anyone know what I can do here? 

 

How can I call the jQuery code again after the partial page refresh? 

 

Ok, here is the scenario...we want to replace our standard Convert button with a custom button that will first call a VF page that has a single field that will be modified on the Lead. The VF page uses the standard Lead Controller and standard Save() method. We want to be able to then direct the user to the Leadconvert.jsp page after save. We created a custom Save() method using an extension class and the redirect works but the problem is I don't know how to pass parameters to populate the URL correctly. Here is the VF page:

<apex:page standardController="Lead" extensions="TeamTrackFlag" sidebar="false">
  <apex:sectionHeader title="Edit Create Team Track Flag"
                      subtitle="{!lead.name}"/>
  <apex:form >
    <apex:pageBlock title="Edit Lead" id="thePageBlock"
                    mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
        <apex:inputField value="{!Lead.Create_TeamTrack__c}" 
              required="true"/>
        <apex:inputField value="{!Lead.ID}" rendered="false" />
    </apex:pageBlock>
  </apex:form> 
</apex:page>

Here is the class:

public class TeamTrackFlag{
    ApexPages.StandardController controller;
        public TeamTrackFlag(ApexPages.StandardController con){
                controller = con;
                     }
                                     
public PageReference save()
 {        controller.save();
         PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}&noopptt={!Lead.Company}-{!Lead.Name}')
         return redirecturl;
             }}

This is the error I get:

Unable to Access Page
Invalid parameter value "{!Lead.Id}" for parameter "id".

Error: The value of the parameter specified above contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and re-submit. If the error still persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.

 
And the URL looks like this:

https://cs3.salesforce.com/lead/leadconvert.jsp?id=%7B%21Lead.Id%7D&noopptt=%7B%21Lead.Company%7D-%7B%21Lead.Name%7D&retURL=%2F%7B%21Lead.Id%7D

Help! I'm an analyst who doesn't do much coding, i'm hoping its a simple fix.