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
avinash dhankeavinash dhanke 

Attempt to de-reference a null object in visualforce page

public without Sharing class SendToContractorController {
    Public Account newAccount {get; set;}
    
    Public String AccountId ; 
    Public String  eventType ;
    
    Public ApexPages.StandardController controller {get; set;}
    
    public SendToContractorController() { 
        AccountId = ApexPages.currentPage().getParameters().get('Id');
        eventType = ApexPages.currentPage().getParameters().get('type');
        
    
        }
    
    
    public PageReference init() {
        try{
            
                if(eventType == 'SentToCustomer') {
                    newAccount.Sent_to_Customer__c = true;
                  //  newAccount.Subcontractor_Email__c = newAccount.Subcontractor_Search__r.Applicant2_Email__c ;
                    
                   update newAccount;
                    
                   // SendToContractorController.processEvent(new set<Id>{newAccount.id});
                    PageReference eventPage = new ApexPages.StandardController(newAccount).view();
                    eventPage.setRedirect(true);
                    return eventPage;
                    
                } else if(eventType == 'SyncDataFromCustomer') {
                    
                    List<Contractor_Job__c> contractorJobList = [SELECT Id, Event_Id__c, Start_Date_Time__c,End_Date_Time__c,Description__c, Status__c, Recharge_Notes__c, Special_Instructions__c 
                                                                 FROM Contractor_Job__c
                                                                 ];
                    system.debug('contractorJobList::'+contractorJobList);
                    SyncSubcontractorData.syncData(contractorJobList);
                    
                    PageReference eventPage = new ApexPages.StandardController(newAccount).view();
                    eventPage.setRedirect(true);
                    return eventPage;
                }
            
        } catch(Exception e){
            ApexPages.addMessages(e);
            
        }
        return null; 
    }
    
Jayant DasJayant Das
This post does not clarify anything around your question or problem but only a code snippet. Providing more information on the forum helps to seek better answers.
Vinod ChoudharyVinod Choudhary
Hi Avinash,

You can use system.debug() statements in your controller code to show you values being returned at different stages.
 
Gaurish Gopal GoelGaurish Gopal Goel
Hi Avinash, Try to initialize your account object in your constructor like this:
public without Sharing class SendToContractorController {
    Public Account newAccount {get; set;}
    
    Public String AccountId ; 
    Public String  eventType ;
    
    Public ApexPages.StandardController controller {get; set;}
    
    public SendToContractorController() { 
        AccountId = ApexPages.currentPage().getParameters().get('Id');
        eventType = ApexPages.currentPage().getParameters().get('type');
        
        newAccount = new Account();
        }

}
avinash dhankeavinash dhanke
yes,thanks
Gaurish Gopal GoelGaurish Gopal Goel
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.