A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 129

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 278

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 149

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 206

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 295

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_database_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_database_driver.php

Line Number: 333

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 284

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 296

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 306

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 318

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 319

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 377

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Session cannot be started after headers have already been sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home1/prizmb9y/public_html/application/core/MY_Controller.php
Line: 16
Function: __construct

File: /home1/prizmb9y/public_html/application/controllers/Frontend.php
Line: 29
Function: __construct

File: /home1/prizmb9y/public_html/index.php
Line: 315
Function: require_once

Blog Details

+91 72594 01072 , +91 9566582294

Query List view Records from Apex & Lightning Comp

Query List view Records from Apex & Lightning Comp

One of the coolest features provided Force.com API to fetch metadata via REST api calls.


The below list of challenges are covered in this blog.

Calling Self org REST API from apex
Using List view metaData
Accessing Session ID from lightning Component

My business scenario is to fetch the list of contacts and create Meeting attendee records for a particular meeting. I don’t want to search or use filter or custom UI. I want to leverage the Salesforce out of the box feature to fetch and process list of Contacts.


Salesforce has list view features to filter the contacts and display them in list view. We can leverage this listview and fetch the records of list view to process from lightning component.


Salesforce metadata API helps to fetch the list view Query and then we can use the Query to fetch records.


String listViewId = ‘AnyContact listview ID’;

       System.debug('The listViewId-->' + listViewId);

       

       HttpRequest req = new HttpRequest();

       HttpResponse res = new HttpResponse();

       Http http = new Http();


           String endPoint = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v45.0/sobjects/Contact/listviews/'+listViewId+'/describe';

           System.debug('The End Point-->' + endPoint);

           req.setEndpoint(endPoint);

           req.setHeader('Authorization', 'Bearer ' + getUserSession());

           req.setHeader('Content-Type', 'application/json');

           req.setMethod('GET');

           req.setTimeout(20000);

           String resp, query;

               res = http.send(req);

               resp = res.getBody();

               ListViewOption lt = (ListViewOption)JSON.deserialize(resp, ListViewOption.class);

               query = lt.query;

           List<sObject> contacts = Database.query(query);


The toughest part is getting the Session ID from lightning Component. The lightning component call to Apex method does not support UserInfo.getSessionID() method. So we need to build a work around to bring Session ID.


We can build a VF page and call the page and getbody of the page from Apex code under Aura enabled method. Now we are able to get the Session ID from VF page.


Apex method to Call from Aura Method

public static String getUserSession(){

       // Refer to the VF Page built with Body contains Session ID

       PageReference reportPage = Page.SessionIDPage;

       // Get the content of the VF page

       String vfContent = reportPage.getContent().toString();

       System.debug('vfContent '+vfContent);

       Integer startP = vfContent.indexOf('Session_ID_Start') + 'Session_ID_Start'.length(),

       Integer endP = vfContent.indexOf('Session_ID_End');

       String sessionId = vfContent.substring(startP, endP);

       System.debug('sessionId '+sessionId);

       return sessionId;

   }


VF Page


<apex:page >

   Session_ID_Start{!$Api.Session_ID}Session_ID_End

</apex:page>


Share
May 23, 2019