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
abhi09abhi09 

Unable to retrieve just inserted lead

Hi All,

public class customcontroller {
-----------------------------------
------------------------------------
--------------------------------------
public PageReference finalnext() {
----------------------
-----------------------
insert ld ; // inserting lead ld
Household(ld.id);
}

public PageReference Household(string id){
pagereference pdfpage = new pagereference('/apex/hoh?leadid='+leadid');
attachment attpdf = new attachment();
attpdf.body = pdfpage.getcontent();
attpdf.name = 'hh.pdf';
attpdf.ContentType = '.pdf';
attpdf.parentid = leadid;
insert attpdf;
}
} // end of controller



hoh visual force controller

public class hohcontroller{

public hohcontroller(){
id leadid=apexpages.currentpage().getparameters().get('leadid');
system.debug('++++++++++++ leadid+++++++++++++++++' +leadid);
lead ld = [select fields from lead where id =: leadid];

}


} // End of hohcontroller

 

If you look at the code, first I am inserting lead ld in the finalnext() then I am calling Household(ld.id) function and passing leadid. In the Household function, I am creating pdf by passing leadid to hoh visual force page.
In the hohcontroller, I can see the leadid in the debug statement but still the query is returning no records. Any help would be appreciated.

Thanks
Abhi

crop1645crop1645

Both methods finalNext() and Household() are supposed to return a PageReference but I see no return statements in either method. In addition, you may need a pdfPage.setRedirect(true) to get the hoh controller to be invoked

abhi09abhi09

 

Thanks crop1645 for your reply

 

         I did not mention here but both the functions have return statements. And the hoh controller method is getting invoked and I can see the leadid in the debug statement.But the soql query is not returning the just inserted lead. 

crop1645crop1645

Have you tried entering the query into SFDC Workbench or Developer Console and executing it there?

 

If the record was inserted successfully by user X then same user X should be able to read the record unless user X doesn't have read access on Leads

abhi09abhi09

Yes, I am getting the record when I execute it in SFDC Workbench.  I solved the issue when I moved the Household(ld.id); function call which is after the lead insertion call  to the next page(I am pasing the leadid to the next page). It is strange why it is not working when I call the  Household(ld.id) immediately after the lead insertion.Any thoughts .....?

 

 

    Thanks crop1645 for your response

 

        

crop1645crop1645

In customController, where is the variable leadId declared and set to ld.id ?

 

BTW - not so easy to read ld.Id as <lead vbl>.<id vbl> -- my own convention is to just use 'l' for Lead ('a' for Account, 'o' for Opportunity, 'c' for Contact, and 'cs' for Case) -- I would encourage you to also adopt some conventions that you apply across all controllers, VF pages, triggers, classes