function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tapas TuloTapas Tulo 

Getting an Field_intigrity_Exception error while Creating a ControllerExtension

Failed to create createContainerMember for containerId=1dc28000000TnhRAAS: This container member belongs to a container that currently has an unfinished save request with deploymentId=1dr280000038Io9. You may not modify any members in this container until it completes.: Metadata Container ID
Best Answer chosen by Tapas Tulo
Shikha AgashiShikha Agashi
you are perfoming DML operation on same record twice. That is why it is throwing error. 

All Answers

Shikha AgashiShikha Agashi
can you please paste your code here?
 
Tapas TuloTapas Tulo
hi sikha,
here my code:-


public class SpeakerControllerExtension {

    public blob picture { get; set; }
    public String errorMessage { get; set; }

    private final Speaker__c speaker;
    private ApexPages.StandardController stdController;

    public SpeakerControllerExtension(ApexPages.StandardController stdController) {
        this.speaker = (Speaker__c)stdController.getRecord();
        this.stdController = stdController;
    }

    public PageReference save() {
        errorMessage = '';
        try {
            upsert speaker;
            if (picture != null) {
                Attachment attachment = new Attachment();
                attachment.body = picture;
                attachment.name = 'speaker' + speaker.id + '.jpg';
                attachment.parentid = speaker.id;
                attachment.ContentType = 'application/jpg';
                insert attachment;
                speaker.Picture_Path__c = '/servlet/servlet.FileDownload?file='
                                          + attachment.id;
                update speaker;
            }
            return new ApexPages.StandardController(speaker).view();
        } catch(System.Exception ex) {
            errorMessage = ex.getMessage();
            return null;
        }
    }
 
Shikha AgashiShikha Agashi
you are perfoming DML operation on same record twice. That is why it is throwing error. 
This was selected as the best answer