0

I am really stuck on this issue and am on a tight/it-was-due-yesterday deadline. I really hope someone has some insight on how to move forward on this.

I have a custom Object: Business_Verification_Summary__c with Fields: CompanyName__c, Credit_Review__c, Lexis_Nexis_Report_Link__c, Status__c, and Transaction_Date__c.

Credit_Review__c is a look up to Credit Review. The rest are text types.

I am querying for these fields by:

bvs = [SELECT Id, Lexis_Nexis_Report_Link__c, Credit_Review__c, Transaction_Date__c, CompanyName__c, Status__c FROM Business_Verification_Summary__c Where Credit_Review__r.Id = :actId]

:actId is the Current Page's Credit Review's Id:

public sendToWebService2(ApexPages.StandardController controller){ actId = controller.getRecord().id;

In my VFP I am pulling out the Data for bvs:

          <div>
              <div>
                   This is the Report link: {!bvs.Lexis_Nexis_Report_Link__c} 
              </div>
          </div>
          <div>
              <div>
                  This is the Report link: {!bvs.CompanyName} 
              </div>
          </div>

The data displays correctly. Which is good, except for when the user logs out of their Salesforce. The data is erased and they have to start over.

I attempted to resolve this by adding in a method that would run on the page loading. The method would check to see if there was any Business_Verification_Summary__c that matched the current page's Credit_Review__c Id. This is where I believe my first issue is, I am not sure that isThereDataAlready() is loading on the page load. In addition, I am not sure if the bvs variable is being picked up on page load.

global class sendToWebService2  
{
public Business_Verification_Summary__c bvs {get;set;}
public sendToWebService2(ApexPages.StandardController controller){
    actId = controller.getRecord().id; //this is getting the Credit_Review__c's Id
    isThereDataAlready();
}

//if this runs we know that there is a record already in the object
public void isThereDataAlready(){
    bvs = [SELECT Id, Lexis_Nexis_Report_Link__c, Credit_Review__c, Transaction_Date__c, Status__c FROM Business_Verification_Summary__c Where Credit_Review__r.Id = :actId LIMIT 1];
    if(bvs.Status__c == 'Completed'){ 
        //save data to variables to be put on VFP
    }
}

//this is the action for the VFP commandButton. If this button shows, it means that there is no matching Business_Verification_Summary__c records
public void pullReport()
{   
    bvsUpdate();
} 

public void bvsUpdate(){
        getAccounts(); //this is the POST and GET callout method
        bvs = new Business_Verification_Summary__c();//creating a new object
        insert bvs;
        bvs.Lexis_Nexis_Report_Link__c = jsonStr; //this data is pulled from getAccounts()
        bvs.Credit_Review__c = actId;
        bvs.Transaction_Date__c = newdate;//this data is pulled from getAccounts()
        bvs.Status__c = 'Completed';
        update bvs;
}

I am not sure if I am way off and I need to do some remoting, angular, or instantiation or if I am close and just need to figure out how to write isThereDataAlready() correctly. Has anyone run into this issue before? How can I pull a report once and maintain the data on that page permanently?

  • can you post the url of the VFP? The controller.getRecord().id picks the id from the vf page. Assume you page has /apex/mypage?id=XXXXXXX, XXXXX will be your ID. As far as isThereDataAlready() method, it will 100% be called because you are calling it in a constructor. To validate add a system.debug at the start of the method and validate if you want to be convinced. – Rao Oct 26 '16 at 17:16
0

I resolved the issue. There were many small adjustments but the largest of them was updating my constructor with the bvs list. As soon as the page loads it can read the string to see if there are values. I originally put the string inside of a method and called that method inside of the constructor which, for some reason, does not translate.

Here is the updated constructor:

public sendToWebService2(ApexPages.StandardController controller){
    actId = controller.getRecord().id;
    try {
        bvs = [SELECT Id, Lexis_Nexis_Report_Link__c, Credit_Review__c, CompanyName__c, Transaction_Date__c, Status__c FROM Business_Verification_Summary__c Where Credit_Review__r.Id = :actId LIMIT 1];
    }
    catch (Exception e){
        system.debug('this is the exception:' + e);
    }
}

I put this in a try catch because if I just left the string in the constructor as is, it would error out every time the page loaded and there was a null value. I needed the catch to catch the null values. The rest is JavaScript to hide the button if there is data listed, and to display the button if there is no data available. The button is then linked to a method that calls the service.

I hope this helps if anyone runs into a similar problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.