Forum Replies Created

Page 47 of 57
  • shariq

    Member
    September 15, 2018 at 1:28 am in reply to: Use Lightning Components in Visualforce Pages in salesforce.

    Hi,

    Lightning app - 

    <aura:application access="GLOBAL" extends="ltng:outApp">
    <aura:dependency resource="c:FlipCard"/>
    </aura:application>

    In above Lightning Application, we have used access as global so that it can be used anywhere in Salesforce organization like Visualforce. extending ltng:outApp indicates that any component defined in this application can be used on Visualforce page.

    Visualforce page - 

    <apex:page >
    <apex:includeLightning />

    <div style="width:30%;height:100px;" id="FlipcardContainer" />

    <script>
    $Lightning.use("c:LightningOutContainerApp", function() {
    $Lightning.createComponent("c:FlipCard",
    {
    borderColor : "#16325c",
    bgColor : "#16325c" ,
    fontColor : "#FFF",
    frontText : "What's cool about Lightning Component Development",
    backText : "You dont need to enable Lightning experience, It will work on Classic Instance as well"
    },
    "FlipcardContainer",
    function(cmp) {
    console.log('Component created, do something cool here');
    });
    });
    </script>
    </apex:page>

    In above Visualforce page, apex:includeLightning tag imports necessary dependencies and scripts to enable Visualforce to act as Lightning component container.

    Hope this helps.

  • shariq

    Member
    September 15, 2018 at 1:21 am in reply to: How can you override a list button with a visuaflorce page?

    Hi,

    You can override the behavior of standard buttons—like New, View, or Edit—in Salesforce Classic, Lightning Experience, and mobile independently. You can also override the tab home page that displays when a user clicks a standard, custom, or external object tab.

    But before overriding there some tips and limitations -

    • If you override a standard button in Salesforce, that button is still available in Connect Offline, but it retains its original behavior.
    • The View standard button refers to all links in Salesforce that display the detail page for a record. Overriding the View standard button reroutes all these links.
    • The View action is the only one that supports overrides with a Lightning record page. To make a Lightning record page available for a View action override, assign the page as the org default for its associated object by activating it in the Lightning App Builder.
    • If you have the View action overridden with a Visualforce page in Salesforce Classic, the Setup menu on that object record page in Lightning Experience displays the Edit Page option. Selecting Edit Page in Lightning Experience on an object page that’s overridden with a Visualforce page in Salesforce Classic lets you create a custom Lightning Experience record page for that object in the Lightning App Builder.
    • If a button isn’t available for overrides, you can still hide it on the page layout.
    • Button overrides affect everywhere that action or behavior is available. For example, overriding the New button on an account also overrides the account option in the Create New drop-down list in the Salesforce Classic sidebar.
    • Person Account records use any standard button overrides you make for accounts. Person Account records also use any overrides for the View Self-Service and Enable Self-Service buttons you make for contacts.
    • If your organization uses the Console tab, overrides for the Edit and View buttons for an object don’t affect the Edit and View buttons in the mini page layouts. Pages that display due to overrides display in the console without the header or sidebar.
    • To replace a standard button with a custom button, first define the custom button, then customize the page layout to hide the standard button and display the custom one in its place
      Because events and tasks don’t have their own tabs, you can only override their standard buttons and links.
    • When you override the Edit button with a Visualforce page, you’re also overriding default logic that checks whether the record has been locked for approval. However, you can perform the same check by implementing the Approval.lock Apex method.

    Limitations

    • You can override buttons on the detail page but not the edit page of a record.
    • You can only override these standard buttons: New, View, Edit, and Delete.
    • You can’t change buttons on lookup dialogs, reports, or tabs. However, you can change the buttons on list view and search result layouts under search layouts.
    • Action overrides on the New standard button don't work on New Object links in lookup searches.
    • You can’t relabel or relocate standard buttons on a record detail page.
    • When overriding tabs or buttons with a Lightning component, you can select only Lightning components that implement the lightning:actionOverride interface.
    • A standard button (New, Edit, View, Delete, and Clone) overridden with a Visualforce page doesn’t show up in the Salesforce app unless the Visualforce page is enabled for Salesforce mobile apps. Overriding standard list and tab controls isn’t supported in mobile.
    • When overriding tabs with a Visualforce page, you can select only Visualforce pages that use the standard list controller for that tab’s associated object, pages with a custom controller, or pages with no controller.
    • When overriding lists with a Visualforce page, you can select only Visualforce pages that use a standard list controller.
    • When overriding buttons with a Visualforce page, you can select only Visualforce pages that use the standard controller for the object on which the button appears. For example, if you want to use a page to override the Editbutton on accounts, the page markup must include the standardController="Account" attribute on the <apex:page> tag.

    Hope this helps.

  • Hi,

    Firstly you should know about sharing record using apex -

    To access sharing programmatically, you must use the share object associated with the standard or custom object for which you want to share. For example, AccountShare is the sharing object for the Account object, ContactShare is the sharing object for the Contact object. In addition, all custom object sharing objects are named as follows, where MyCustomObject is the name of the custom object:

    MyCustomObject__Share

    Objects on the detail side of a master-detail relationship do not have an associated sharing object. The detail record’s access is determined by the master’s sharing object and the relationship’s sharing setting. For more information, see “Custom Object Security” in the Salesforce online help.

    A share object includes records supporting all three types of sharing: managed sharing, user managed sharing, and Apex managed sharing. Sharing granted to users implicitly through organization-wide defaults, the role hierarchy, and permissions such as the “View All” and “Modify All” permissions for the given object, “View All Data,” and “Modify All Data” are not tracked with this object.

    And the answer for your question is -

    A. By querying CustomObject__share
    B. By querying the role hierarchy.
    C. By calling the isShared() method for the record
    D. By calling the profile settings of the current user

    Hope this helps.

  • Hi,

    To add more -

    The minimum value to see any debug logs is a System level of ERROR, but most people only use the default logging level, so the usual recommendation is DEBUG. To debug at a lower level than debug, use the two parameter version of System.debug:

    System.debug(LoggingLevel.ERROR, somemessage);
    Also note, logs over 2mb may be truncated, including your debug messages.

    Hope this helps.

  • shariq

    Member
    September 15, 2018 at 1:04 am in reply to: Please provide some solution i am having this kind of error

    Hi,

    Reason behind the problem was - you have not included the jquery library and you were using its methods on js.

    Best practice is to save that library in static resource rather using it directly on page.

    Hope this helps.

  • shariq

    Member
    September 15, 2018 at 1:00 am in reply to: What do you think is the disadvantage of Salesforce, if any?

    Hi,

    As a developer point of view -

    Disadvantages :-

    • Apex is a proprietary language. Other than the force.com Eclipse plugin, there's little to no tooling available such as refactoring, code analysis, etc.
    • Apex was modeled on Java 5, which is considered to be lagging behind other languages, and without tooling (see #1), can be quite cumbersome.
    • Deployment is still fairly manual with lots of gotchas and manual steps. This situation is slowly improving over time, but you'll be disappointed if you're used to having automated deployments.
    • Apex lacks packages/namespaces. All of your classes, interfaces, etc. live in one folder on the server. This makes code much less organized and class/interface names necessarily long to avoid name clashes and to provide context. This is one of my biggest complaints, and I would not freely choose to build on force.com for this reason alone.
    • The "force.com IDE", aka force.com eclipse plugin, is incredibly slow. Saving any file, whether it be a class file, text file, etc., usually takes at least 5 seconds and sometimes up to 30 seconds depending on how many objects, data types, class files, etc. are in your org. Saving is also a blocking action, requiring not only compilation, but a full sync of your local project with the server. Orders of magnitude slower than Java or .NET.
    • The online developer community does not seem very healthy. I've noticed lots of forum posts go unanswered or unsolved. I think this may have something to do with the forum software salesforce.com uses, which seems to suck pretty hard.
    • The data access DSL in Apex leaves a lot to be desired. It's not even remotely competitive with the likes of (N)Hibernate, JPA, etc.
    • Developing an app on Apex/VisualForce is an exercise in governor limits engineering. Easily half of programmer time is spent trying to optimize to avoid the numerous governor limits and other gotchas like visualforce view state limits. It could be argued that if you write efficient code to begin with you won't have this problem, which is true to an extent. However there are many times that you have valid reasons to make more than x queries in a session, or loop through more than x records, etc.
    • The save->compile->run cycle is extremely slow, esp. when it involves zipping and uploading the entire static resource bundle just to do something like test a minor CSS or javascript change.
      In general, the pain of a young, fledgling platform without the benefits of it being open source. You have no way to validate and/or fix bugs in the platform. They say to post it to their IdeaExchange.

    Pros of Salesforce:

    Customizable dashboard. When you log in, the tool’s dashboard gives you a huge range of report widgets, allowing you to have a bird’s-eye perspective of how your company is performing. Your sales reps can check out real-time summaries of customer data and other relevant statistics.

    Easy-to-navigate software. The software is also easy to navigate. A simple navigation bar exists at the top of the window. The tabs are separated into various categories, such as Home, Accounts, Contacts, Leads, Opportunities, Campaigns, Forecasts Files, among others.

    Social capabilities. The tool’s social media function and news feed operate very much like Facebook, thus making it very familiar as well as easy to use for users. You can quickly browse the news feed and immediately post status updates, share links, and upload files right from the dashboard.

    Hope this helps.

     

  • shariq

    Member
    September 15, 2018 at 12:52 am in reply to: Why do we need Account Hierarchy in Salesforce?

    Hi,

    The account hierarchy shows you the accounts that are associated through the Parent Account field, giving you a global view of a company and its subsidiaries. In the hierarchy, accounts are indented to show that they are subsidiaries of the parent account above them.

    To view the account hierarchy, click View Hierarchy next to the account name on the account detail page. The Account Hierarchy page displays up to 500 child accounts. If you don’t have access to certain accounts that appear on the Account Hierarchy page, the columns for those accounts won’t display details

    To list an account as a subsidiary, edit the subsidiary account and type the name of an existing account in the Parent Account field. Alternatively, you can click the lookup icon to search for (or optionally, create) a parent account.

    The parent account must be an existing account before it can be entered and saved in this field.

    For companies with multiple office locations, you can also use the Account Site field to distinguish among the locations.

    If your organization uses divisions, accounts that are associated via the Parent Account field do not need to be in the same division.

    The Parent Account field and the View Hierarchy link are not supported for person accounts.

    Hope this helps.

  • shariq

    Member
    September 15, 2018 at 12:49 am in reply to: Action poller in visualforce

    Hi,

    In the following example action poller calls the method "CounterMethod" every 5 seconds where the variable "seconds" counter is updated. Rerender attribute refreshes the page block hence showing the updated value of variable "seconds".

    Controller Class:
    Public with sharing class actionpollerDemoController {
    Public  Integer seconds{get;set;}
    Public actionpollerDemoController(){
    seconds = 0;
    }

    Public void CounterMethod(){
    seconds = seconds + 5;
    }
    }

    Visualforce Page:

    <apex:page controller="actionpollerDemoController">
    <apex:form >
    <apex:pageBlock id="pgplck">
    <apex:actionPoller action="{!CounterMethod}" reRender="pgplck" interval="5"/>
    {!seconds } seconds since the action poller was called !!
    </apex:pageBlock>
    </apex:form>
    </apex:page>

    Hope this helps.

  • Hi,

    It can only have auto number type or text type.

    You can set a format of auto number  for example-[a0000],[a0001]etc

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:56 pm in reply to: what is the use of setStorable() in Salesforce?

    Hi,

    The setStorable function takes an optional argument, which is a configuration map of key-value pairs representing the storage options and values to set. You can only set the following property:

    ignoreExisting
    Set to true to bypass the cache. The default value is false.
    This property is useful when you know that any cached data is invalid, such as after a record modification. This property should be used rarely because it explicitly defeats caching.
    To set the storage options for the action response, pass this configuration map into setStorable(configObj).
    Lifecycle of Storable Actions
    This image describes the sequence of callback execution for storable actions.
    Enable Storable Actions in an Application
    Storable actions are automatically configured in Lightning Experience and the Salesforce mobile app. To use storable actions in a standalone app (.app resource), you must configure client-side storage for cached action responses.
    Storage Service Adapters
    The Storage Service supports multiple implementations of storage and selects an adapter at runtime based on browser support and specified characteristics of persistence and security. Storage can be persistent and secure. With persistent storage, cached data is preserved between user sessions in the browser. With secure storage, cached data is encrypted.
    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:47 pm in reply to: What is the use of renderIf in Salesforce lightning component?

    Hi,

    It is basically used for show and hide the components.

    To add more - aura:renderIf  is deprecated as I read on developer.salesforce, use aura:if

    <aura:component>
    <aura:if isTrue="{!v.truthy}">
    True
    <aura:set attribute="else">
    False
    </aura:set>
    </aura:if>
    </aura:component>

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:42 pm in reply to: How to retrieve all custom objects from Ant Migration in Salesforce?

    Hi,

    For Standard Objects :-

    <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
    <members>Account</members>
    <name>CustomObject</name>
    </types>
    <version>40.0</version>
    </Package>

    For Custom Objects :-

    <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
    <members>*</members>
    <name>CustomObject</name>
    </types>
    <version>40.0</version>
    </Package>

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:36 pm in reply to: Can we create a field on Person Account directly in Salesforce?

    Hi,

    The __pc stands for person contact and are custom fields in the Contact object.

    This is how it works: a Person Accounts is also considered a Contact in the salesforce back-end, therefore, person accounts have an Account Id and a Contact Id. Every custom field created in the Contact object is available for Person Accounts using the __pc. If you want a field for person account only create the field in the Contact object.

    Hope this helps.

  • Hi,

    You can convert a Person account to Business Account or vice versa.

    Unlike business accounts, person accounts do not have a Contacts related list. However, you can use the Partners related list to track relationships between different person accounts.

    • Or you can try this
    • Just Convert a person account to a business account keeping all the info attached to the old person account to the contact.Run a report Account + Contact and Get Account and Contact IDs ( Do not use the URL that you have for the person account record as that ID belongs to the persona account and its kind of a new ID)
    • Find a record type ID that you want to use for the new account - Go to Setup - Account - Record Type - Select one type and copy the ID from the URL.
    • Find a record type ID that you want to use for the new contact - Same as above but with contact object
    • Change Account record Type to the new account record type through the data loader.
    • Change Contact record Type to the new record type through the data loader.

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:32 pm in reply to: How can we insert records in custom object from standard object

    Hi,

    You need to write the trigger on one object in insert case and in that trigger insert your another object.

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:30 pm in reply to: What is meant by bulkifying trigger?

    Hi,

    To get it more simple bulkifying means that it should work for multiple records.

    The term bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. When a batch of records initiate Apex, a single instance of that Apex code is executed, but it needs to handle all of the records in that given batch. For example, a trigger could be invoked by an Force.com Web Services API call that inserted a batch of records. Or a custom Apex Web Service. So if a batch of records invokes the the same Apex code, all of those records need to be processed as a bulk, in order to write scalable code and avoid hitting governor limits.

    for example :-

    trigger accountTestTrggr on Account (before insert, before update) {

    List<String> accountNames = new List<String>{};

    //Loop through all records in the Trigger.new collection
    for(Account a: Trigger.new){
    //Concatenate the Name and billingState into the Description field
    a.Description = a.Name + ':' + a.BillingState
    }

    }

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:26 pm in reply to: Apex in salesforce

    Hi,

    If not declared explicitly, classes are always With Sharing.

    It is important to understand that in both cases (With or Without Sharing), Apex runs in System Mode, so it wouldn't respect things like Field Level Security.

    Use With Sharing when the User has access to the records being updated via Role, Sharing Rules, Sales Teams - any sort of sharing really.

    Without Sharing is reserved for cases where the User does not have access to the records, but there is a need to update them based on user input.

    Also the With / Without Sharing commutes and if a class doesn't have an explicit declaration, the sharing context of the calling class is inherited.

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:24 pm in reply to: System.Query Exception

    Hi,

    Any error related to query will give this exception.

    for example:-

    1. String not correctly setup in dynamic query - 'select id from contact where id = 'testId''

    How to handle it-

    When attempting to fetch a single record from the database it is easy to run into the above exception. I’ve seen two schools of thought in dealing with this issue – mostly in the forums – and have been hoping to find a more official standpoint.

    I’ll describe the patterns and perhaps you can help me decide.

    The Try-Catch Pattern

    Surround your query by a try-catch block.
    Fetch the record into a single object type variable.
    Either the query successfully executes, or the exception is caught and you deal with it appropriately.
    An example,

    MyObject__c obj;

    try{

    obj = [SELECT id FROM MyObject__c WHERE name=:previouslyDefinedVar];

    } catch(System.QueryException e){

    // Perform logic here

    }
    The Only Use Lists For Query Results Pattern

    Fetch records into Lists of objects. Do this even if you only expect a single row to be returned. [Queries that return values into Lists do not throw the above exception]
    Check the size of the list(perhaps with an if-statement) and only perform required actions on the record if the list has a size of 1.
    List<MyObject__c> objects = [SELECT id FROM MyObject__c WHERE name=:previouslyDefinedVar];

    if(objects.size()==1){

    // Perform Logic

    }

    Hope this helps.

     

     

  • shariq

    Member
    September 14, 2018 at 10:17 pm in reply to: de-reference a null object

    Hi,

    Mostly this error occurs when you have not initialize the list/set/map etc and using their methods.

    When you query any sobject with no records and then using its fields somewhere in code without null or empty check

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:06 pm in reply to: What is the difference between SLDS and Aura Components?

    Hi,

    Differences Between SLDS and Aura :-

    FRAMEWORK:

    First of all Salesforce Lightning Design System is a CSS based framework.
    Used for creating dynamic apps while on the other hand Lightning Components Framework  uses aura components for creating the dynamic apps.

    CONTROLLERS:

    In case of Lightning Components Framework We need to write two Controllers    one for client side and the other one for server side. while in case of Salesforce Lightning Design System we need to write only one controller which will be a server side controller.
    Note:The client side Controller that we will write for Lightning Components Framework would be written using java script while the server side controller will be written using apex.

    SALESFORCE DATA:

    By using Lightning Components Framework we can build an app which will be completely independent of salesforce data while in case of Salesforce Lightning Design System(SLDS) do need some salesforce data which can be accessed using Javascript Remote Objects.

    CLIENT CENTRIC:

    Lightning Components Framework are client-side centric while Salesforce Lightning Design System are server-side centric.

    PERFORMANCE:

    Because Lightning Components are client side centric therefore they are better.
    Equipped for creating dynamic web apps then Salesforce Lightning Design System.

    MOBILE FRIENDLY:

    As mentioned above  Lightning Components are client side centric therefore they are more mobile friendly as compared to the Salesforce Lightning Design  System(SLDS).

    EVENT DRIVEN PROGRAMMING:

    In Lightning Component Framework Event Driven programming such as Javascript and java swing is used for writing helpers which responds to Interface events as they occur but in Salesforce Designing System there is no such concept of Event Driven Programming.

    COMPLEXITY:

    Because In the Lightning Component Framework we need to create two controllers and also it uses  event driven programming language such as  Javascript therefore it is much for complex as compared to the Salesforce Lightning Design System(SLDS)

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 10:02 pm in reply to: What are the different components of WSDL in Salesforce?

    Hi,

    To add more -

    Salesforce provides a WSDL (Web Service Description Language) files. They are called "Enterprise WSDL" and "Partner WSDL". A WSDL is an XML-document which contains a standardized description on how to communicate using a web service (the Salesforce API is exposed as a web service).

    A WSDL is an XML document that describes a web service. It actually stands for Web Services Description Language. SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications

    There components -

    Data types − These are in the form of XML schemas.
    Message − It is an abstract definition of the data, in the form of a message which can be either as a document or as arguments.
    Operation − It is the abstract definition of the operation for a message.
    Port type − It is set of operations mapped to one or more end-points, also defining the collection of operations for a binding.
    Binding − It is the protocol and data formats for the operations that are defined for a particular port type.
    Port − It is a combination of a binding and a network address.

    Hope this helps.

     

  • shariq

    Member
    September 14, 2018 at 9:59 pm in reply to: What are the different elements of WSDL documents in Salesforce?

    Hi,

    components of WSDL are:

    Types: This defines the message data types, which are in the form of XML schema, used by the web services.
    Message: This defines the data elements for each operation where messages could be the entire document or an argument that is to be mapped.
    Port Type: There are multiple services present in WSDL. Port type defines the collection of operations that can be performed for binding.
    Binding: Determines and defines the protocol and data format for each port type.
    Operations: This defines the operations performed for a message to process the message.

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 9:55 pm in reply to: why formula fields are useful

    Hi,

    Formula & Cross Object Formula Field in Salesforce: Formula Field is a read only field whose value is evaluated from the formula or expression defined by us. We can define formula field on both standard as well as custom objects. Any change in expression or formula will automatically update the value of formula field.

    It is a read only field, the value of formulafiled evaluate from expression defined by us. If we update any value in the expression, it automatically updates formula field value. We can create formula fields in both standard and custom object.

    We can return formule result in 7 ways those are:

    1. Checkbox: Calculate a boolean value
    2. Currency: Calculate a dollar or other currency amount and automatically format the field as a currency amount.
    3. Date: Calculate a date, for example, by adding or subtracting days to other dates.
    4. Date/Time: Calculate a date/time, for example, by adding a number of hours or days to another date/time.
    5. Number: Calculate a numeric value.
    6. Percent: Calculate a percent and automatically add the percent sign to the number.
    7. Text: Create a text string, for example, by concatenating other text fields.

    Creating this type of filed is like creating a normal salesforce field with data type formulae and we need to select result typed & provide expression.

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 9:53 pm in reply to: What are expressions used in pages to bind in controllers?

    Hi,

    There are two ways -

    1. Using Getter Setter Variables.
    2. Using 'get'+method name or 'set'+method name

    Example -

    public String str{get;set;}//Use {!str }in vf page

    public String getAllValues(){

    //return string

    return str2;

    }//Use {!AllValues}

    Hope this helps.

  • shariq

    Member
    September 14, 2018 at 9:47 pm in reply to: Limitations of using a Savepoint in apex

    Hi,

    All requests are delimited by the trigger, class method, Web Service, Visualforce page or anonymous block that executes the Apex code. If the entire request completes successfully, all changes are committed to the database. For example, suppose a Visualforce page called an Apex controller, which in turn called an additional Apex class. Only when all the Apex code has finished running and the Visualforce page has finished running, are the changes committed to the database. If the request does not complete successfully, all database changes are rolled back.

    Sometimes during the processing of records, your business rules require that partial work (already executed DML statements) be “rolled back” so that the processing can continue in another direction. Apex gives you the ability to generate a savepoint, that is, a point in the request that specifies the state of the database at that time. Any DML statement that occurs after the savepoint can be discarded, and the database can be restored to the same condition it was in at the time you generated the savepoint.

    The following limitations apply to generating savepoint variables and rolling back the database:

    • If you set more than one savepoint, then roll back to a savepoint that is not the last savepoint you generated, the later savepoint variables become invalid. For example, if you generated savepoint SP1 first, savepoint SP2 after that, and then you rolled back to SP1, the variable SP2 would no longer be valid. You will receive a runtime error if you try to use it.
    • References to savepoints cannot cross trigger invocations because each trigger invocation is a new trigger context. If you declare a savepoint as a static variable then try to use it across trigger contexts, you will receive a run-time error.
    • Each savepoint you set counts against the governor limit for DML statements.
    • Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.
    • Each rollback counts against the governor limit for DML statements. You will receive a runtime error if you try to rollback the database additional times.
    • The ID on an sObject inserted after setting a savepoint is not cleared after a rollback. Create an sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject is not in the database and, thus, cannot be updated.

    Example -

    Account a = new Account(Name = 'xxx'); insert a;
    System.assertEquals(null, [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
    AccountNumber);

    // Create a savepoint while AccountNumber is null
    Savepoint sp = Database.setSavepoint();

    // Change the account number
    a.AccountNumber = '123';
    update a;
    System.assertEquals('123', [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
    AccountNumber);

    // Rollback to the previous null value
    Database.rollback(sp);
    System.assertEquals(null, [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
    AccountNumber);

    Hope this helps.

Page 47 of 57