You need to sign in to do that
Don't have an account?
Please Help: Display error on Visualforce page depending on checkbox value
Hey All ,
I have a visualforce page which allows the user to enter a part number in the UI and click a submit button. The system then goes to the compliance part object and uses data from that record to generate some compliance certificates (.pdf) that the user can then print.
I’d like to update this to interrupt this process: Instead of simply generating and displaying the certificate back to the user, I’d like the application to first check for the “Reviewed_By_Compliance_Team__c”(its a checkbox on part_compliance__c object) on the part compliance record associated with the part number entered by the user. If FALSE, display a message saying. “Under Review:Please check back in 7 days”.And , It should not display copliance Certificate page.
Below is the Apex class corresponding to the visulaforce page:-
public with sharing class ProductComplianceRequestController {
public String partNumber {get;set;}
public ProductComplianceRequestController() {
}
public PageReference requestCompliance() {
list<Product2> part = [Select Id From Product2 Where Part_Number__c =: partNumber];
if(part.size() == 0) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Part not found.'));
return null;
}
return new Apexpages.Pagereference('/apex/ProductComplianceCertificate?id=' + part[0].Id);
}
static testMethod void testRequest() {
Product2 testPart = new Product2();
testPart.Part_Number__c = 'E000000';
testPart.Name = 'E000000';
insert testPart;
ProductComplianceRequestController controller = new ProductComplianceRequestController();
controller.partNumber = testPart.Part_Number__c;
test.startTest();
String resultURL = controller.requestCompliance().getUrl();
test.stopTest();
System.assertEquals('/apex/ProductComplianceCertificate?id=' + testPart.Id, resultURL);
}
static testMethod void testRequestNotExist() {
Product2 testPart = new Product2();
testPart.Part_Number__c = 'E000000';
testPart.Name = 'E000000';
insert testPart;
Pagereference pageRef = Page.ProductComplianceRequest;
Test.setCurrentPage(pageRef);
ProductComplianceRequestController controller = new ProductComplianceRequestController();
controller.partNumber = 'E000001';
test.startTest();
controller.requestCompliance();
test.stopTest();
System.assertEquals(ApexPages.getMessages().size(), 1);
}
}
It seems like you have two part compliance records with the same part name, can you please check the debug log and confirm the one which you are looking is the one we are using in this code.
Can you copy the debug log?
All Answers
Try this.
Hey ,
Thanks for the reply . It is showing no error in class . But when I open a VF page and enter a valid product code. It is showing this error:-
List has no rows for assignment to SObject
<apex:PageblockSectionItem >
<apex:inputText value="{!partNumber}" />
<apex:commandButton action="{!requestCompliance}" value="Get Statement"/>
</apex:PageblockSectionItem>
If possible can you post the debug log for this code?
This is the line causing error... Can you check whether there is a part compliance record, for this particular part number.??
hey ,
When I don't insert the below code. Its working fine and able to fetch the data .
else
{
Part_Compliance__c pc = [SELECT Id, Reviewed_By_Compliance_Team__c FROM Part_Compliance__c WHERE Part_Number__c = :partNumber];
if(pc.Reviewed_By_Compliance_Team__c == True)
{
return new Apexpages.Pagereference('/apex/ProductComplianceCertificate?id=' + part[0].Id);
}
else
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'Under Review:Please check back in 7 days.'));
return null;
}
I don't know what to do. Kindly help out .
Reviewed_By_Compliance_Team__c”(its a checkbox on part_compliance__c object) on the part compliance record associated with the part number entered by the user
The above code is to check for the Reviewed_By_Compliance_Team__c checkbox value on the part Compliance record. But it seems that there is no record exist for the part number and what should the user be displayed if there is no Part Compliance record for the part number entered by the user.
Hey ,
The record for the part number do exsists . And if the record doesn't exsist it should display " record not found".
Can you try this and copy the debug log.
If you have not solved this issue please try this.
Heyt Naidu ,
Thanks for the reply . But its not working with this code also . Its giving the same error which it is giving in previous codes.
Regards
can you copy the debug log for this.
I think the problem might be... we are looking for part compliance with part Number ( String ) instead of Id.
Can you provide me the debug log once agian to confirm that our search criteria is what we needed.
Did you update the code in your org with the one i gave above, i dont see the log for the line below.
can you update the code and post the debug log.
We are comparing the id with a string and so it is not returning any rows.
I guess this code would work.
can you post the debug log. sorry to ask you so many times but want to confirm the results you get.
try this. this will work.
gud luck.
Hey Naidu ,
All the time this code is only executing one part giving error" Under review:please check back in 7 days". Even though the Reviewed_by_compliance_team__c is checked , still gives the "Under review " error. In short , it is not directing me to the compliance certificate page.
Regards
It seems like you have two part compliance records with the same part name, can you please check the debug log and confirm the one which you are looking is the one we are using in this code.
Can you copy the debug log?
I guess these logs were not for the updated code...
can you please check it... i have added couple of debug statements to check for number of compliance records for the part number...
I see there are two records and my guess would be it is checking for the first record which has the value as false,
Is this a valid data of having two part compliance records for same part number? if not delete one record, or else we need to update the code based on which compliance record we need to choose from the part number.
Hey Naidu ,
You are right . There were 2 records corresponding to that ID . Your code is working fine. I really appreciate your time and deeply express my gratitude for helping me fix the bug. I owe you. You are a salesforce Rockstar....I salute....
Thanks a lot....