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
Michelle Chaplin RegalMichelle Chaplin Regal 

Illegal assignment from void to object

I have a visualforce page extension that's throwing up an error:

Visualforce Error
Exception: Illegal assignment from void to Pick_Run__c
Error occurred loading controller 'newpickrun' for page createpickrun
 
public with sharing class newpickrun {

    public Integer OpenShipmentsCount { get; set; }
    public Integer PriorityShipmentsCount { get; set; }
    public Integer PrevBackorderedCount { get; set; }
    public string DebugLog { get; set; }
    private ApexPages.StandardController ctrl;
    public Pick_Run__c pickrun;

    public newpickrun(ApexPages.StandardController controller) {
        // setup controller
        ctrl = controller;
        pickrun = (Pick_Run__c)ctrl.getRecord();
        GetOpenShipmentInfo();
        GetOtherInfo();
    }

    public void customSave() {
        System.debug('before upsert');
        
        upsert pickrun;
        
        System.debug('after upsert');

        // debug to see the object
        DebugLog = JSON.serialize(pickrun);

        // now that the pickrun has been created, populate all the quotes that
        // meet the criteria on the record
        //PickRunExt.AddQuotesToPickrun(pickrun);
        PickRunExt.GetPickrunDetails2(pickrun);
        
        // redirect with the id to refresh (will probably be a seperate page later)
        //PageReference redirect = Page.picklist;  // Commented on 28-APR-2016: Point #3
       /* PageReference redirect = Page.picklist_WIP;
        redirect.getParameters().put('id', pickrun.Id);
        system.debug('---@@@pickrun'+ pickrun);
        return redirect;*/
        
       //update picked = true
       List<Pick_Run_Detail__c> pickRunDetailsList = new List<Pick_Run_Detail__c>();
       try {
            if(pickRun.Status__c != 'Done') {
                pickRunDetailsList = [select id, Picked__c,Recommended_Whse__c,Recommended_FPick__c from Pick_Run_Detail__c where Pick_Run__c =: pickrun.id ];
                system.debug('----###pickRunDetailsList ---------'+pickRunDetailsList.size() );
                for( Pick_Run_Detail__c pikRun :pickRunDetailsList ){
                 pikRun.Picked__c  = true;
                 pikRun.From_FPick__c = pikRun.Recommended_FPick__c; 
                 pikRun.From_Warehouse__c = pikRun.Recommended_Whse__c;
                }
                update pickRunDetailsList;
           }
        }
        catch(Exception e) {
            System.debug('------inside catch');
            throw e;
        }

        // redirect to the view page for right now until the other page is ready
        //return null; //ctrl.view();
    }
    
      public PageReference goToPickRunDetail() {
        System.debug('before closing...');
        //called for close PickRun
        pickRun = PickrunExt.ClosePickrun(pickRun.Id);
        System.debug('after closing...');  
        //pagereference pr = new pagereference('/' + pickRun.id); // Commented as Point # 2 10-MAY-2016
        
        PageReference redirect = Page.picklist;
        redirect.getParameters().put('id', pickrun.Id);
        return redirect;
    }
        

    public void GetOpenShipmentInfo() {

        List<Quote> quotes = [
            SELECT  Close_Date__c 
            FROM    Quote 
            WHERE   Status = 'Open'
            ORDER BY Close_Date__c ASC
            LIMIT 10000
        ];

        OpenShipmentsCount = quotes.size();
        pickrun.Maximum_Number_of_Orders__c = OpenShipmentsCount;
        pickrun.Earliest_Order_Date__c = quotes.size() == 0 ? null : quotes[0].Close_Date__c;
        pickrun.Latest_Order_Date__c = System.today();
    }

    private void GetOtherInfo() {
        PriorityShipmentsCount = [SELECT COUNT() FROM Quote WHERE Priority_Shipment__c = true AND Status = 'Open'];
        PrevBackorderedCount = [SELECT COUNT() FROM Quote WHERE Previously_on_Backorder__c = true AND Status = 'Open'];
        pickrun.Number_of_Priority_Shipments__c = PriorityShipmentsCount;
        pickrun.Number_of_Previously_Backordered__c = PrevBackorderedCount;
    }
}

To top it all off, this code works fine in my partial copy sandbox, so I don't know what's causing it to throw an error in production.
 
GauravGargGauravGarg
Hi Michael,

In production org, class "PickrunExt" has return type as "void". Please change it to "pick_run__c".

Hope this will solve your problem.

Thanks,
Gaurav
Manish BhatiManish Bhati
Hi Michelle,

The Problem could be in Line No. 13 :-
pickrun = (Pick_Run__c)ctrl.getRecord();
The Controller ctrl which was getting record in partial copy sandbox (as it would be having data), is not able to get data in Production (as you may have just deployed and data is yet to be input for this functionality).

Hence ctrl.getRecord() would be returning null.
I supposed this because you didn't give Line Number in the error, also Illegal assignment error generally comes when there is some typecasting errror.

So, here void is assigned to Pick_Run__c.

Hope this could help.