• Dan Blackhall.ax1171
  • NEWBIE
  • 30 Points
  • Member since 2011

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

I've created this test controller to illustrate my problem

 

public class TestController {
	List<Object_A__c> Aobjects { get; set; }
	List<Object_B__c> Bobjects { get; set; }

	public TestController() {
		//assign values to the a and b lists
	}

	public PageReference pageAction() {
		Savepoint sp = Database.setSavepoint();
		try {
			//Assume this dml operation succeeds
			insert Aobjects;
			//assume this dml operation fails
			insert Bobjects;
		} catch(System.DmlException e) {
			Database.rollback(sp);
			ApexPages.addMessages(e);
		}
	}
}

 

When the pageAction is called and there is a rollback because of a problem with 'B objects', the list of 'A Objects' still have Id values.

 

This becomes a problem when the pageAction is called a second time, because the 'A objects' have Ids and an insert is performed, giving the error: Record ID: cannot specify Id in an insert call

 

What is the best way to solve this?

 If @isTest(SeeAllData=false) working for anyone?

I have annotated the class as well as the method but the testmethod can see the existing data.

Here is simple code snippet. Assertion is getting failed for me...

@isTest(SeeAllData=false)
private class testAnnotationSeeAllData {

static testmethod void myUnitTest()
{
Test.startTest();
List<User> lstUsers = [Select Id, Name From User Where IsActive= true Limit 100];
System.assert(lstUsers.size() == 0);
Test.stopTest();
}
}

tried in api version 24 and 25 both. and Developer Org and Sandbox.


is there anyone who is experiencing the same problem?

I've created this test controller to illustrate my problem

 

public class TestController {
	List<Object_A__c> Aobjects { get; set; }
	List<Object_B__c> Bobjects { get; set; }

	public TestController() {
		//assign values to the a and b lists
	}

	public PageReference pageAction() {
		Savepoint sp = Database.setSavepoint();
		try {
			//Assume this dml operation succeeds
			insert Aobjects;
			//assume this dml operation fails
			insert Bobjects;
		} catch(System.DmlException e) {
			Database.rollback(sp);
			ApexPages.addMessages(e);
		}
	}
}

 

When the pageAction is called and there is a rollback because of a problem with 'B objects', the list of 'A Objects' still have Id values.

 

This becomes a problem when the pageAction is called a second time, because the 'A objects' have Ids and an insert is performed, giving the error: Record ID: cannot specify Id in an insert call

 

What is the best way to solve this?

Hi,

 

I am deseralizing the json string into an object which contains a list of another object, and getting this error:

 

Internal Salesforce Error: 17692538-4726 (1351590007) (1351590007) 



My code has been working up until this Wednesday. Was there any change that has been applied to cs2 env? This the test code I have:

 

public with sharing class JSONTest {
    public class InvoiceStatement {
        Long invoiceNumber;
        Datetime statementDate;
        Decimal totalPrice;
       
        public InvoiceStatement(Long i, Datetime dt, Decimal price)
        {
            invoiceNumber = i;
            statementDate = dt;
            totalPrice = price;
        }
    }
   
    public class InvoiceStatementResponse {
        Integer errorCode;
        List<InvoiceStatement> statements;
       
        public InvoiceStatementResponse(Integer errorCode) {
            this.errorCode = errorCode;
            statements = new List<InvoiceStatement>();
        }
    }
   
    public static void SerializeRoundtrip() {
        Datetime dt = Datetime.now();
        // Create a few invoices.
   
        InvoiceStatement inv1 = new InvoiceStatement(1,Datetime.valueOf(dt),1000);
        InvoiceStatement inv2 = new InvoiceStatement(2,Datetime.valueOf(dt),500);
        // Add the invoices to a list.
   
        List<InvoiceStatement> invoices = new List<InvoiceStatement>();
        invoices.add(inv1);
        invoices.add(inv2);
        
         InvoiceStatementResponse resp = new InvoiceStatementResponse(0);
         resp.statements = invoices;
                 
        String JSONString = JSON.serialize(resp);
        System.debug('Serialized list of invoices into JSON format: ' + JSONString);
       
        InvoiceStatementResponse dresp = (InvoiceStatementResponse)JSON.deserialize(JSONString, InvoiceStatementResponse.class);
        System.debug('dresp=' + dresp);
    }
   
    private static testmethod void mytest() {
        JSONTest.SerializeRoundtrip();
    }
   
}

 

Any help is appreciated.

 

 



When performing a SOQL query from Apex using the FOR UPDATE option, is the locking mechanism optimistic or pessimistic? In other words, if another user attempts to write to the same record, while it is locked FOR UPDATE by another user, will they wait (optimistic), or will they be returned an error immediately (pessimistic).

 

thanks in advance,

 

Chris

We're calling apex:outputLink from within a component, passing in our Site's current URL (which already contains a parameter). The VF code looks like this:


<p>{!$CurrentPage.URL}</p>
<apex:outputLink value="{!$CurrentPage.URL}" styleClass="entryLink">
<apex:param name="id" value="{!entryId}" />
<apex:outputText value="{!entryTitle}" styleClass="entryTitle" />
</apex:outputLink>

The generated HTML source code looks like this:


<p>http://our-developer-edition.na6.force.com:80/apex/MySite__WebPage?page=Loop</p>
<a href="http://our-developer-edition.na6.force.com:80/apex/MySite__WebPage?page=Loop%3Fid=a0880000005PiWOAA0" class="entryLink"><span class="entryTitle">A Third Entry</span></a>

Surely that's the wrong escaping that's happened inside the href tag of the "&". Shouldn't the output look like this: (I've used bold to show the difference)


<p>http://our-developer-edition.na6.force.com:80/apex/MySite__WebPage?page=Loop</p>
<a href="http://our-developer-edition.na6.force.com:80/apex/MySite__WebPage?page=Loop&amp;id=a0880000005PiWOAA0" class="entryLink"><span class="entryTitle">A Third Entry</span></a>

Is there a quick/safe way round this problem when you don't know if your outputLink's value contains parameters or not?

  • September 14, 2009
  • Like
  • 0