You need to sign in to do that
Don't have an account?
Aditya Pavan lakshmi
Error in the Production trying to replicate the same in sandbox
Hi,
I am getting the error in the production,please help me how to figure out the issue in the sandbox.
Please Check the below screen shot and Kindly help me
Thanks &Regards,
Pavan Vempati
I am getting the error in the production,please help me how to figure out the issue in the sandbox.
Please Check the below screen shot and Kindly help me
Thanks &Regards,
Pavan Vempati
Please share the code of your Apex Class SetToWonController in order to understand what is failing.
Regards
Medhya Mahajan
You are getting a null pointer exception when a user is clicking on the Save button on the set_to_won visulaforce page which is calling Save method written in the Apex class SetToWonController. The method is not getting data (e.g. Id of the record) to process when it is called.
You need to look into the logic of the method and also do the null pointer exception handling for the same.
Thanks,
Shobit
Please look and help me to figure it out.
public class SetToWonController {
public Id OpportunityId;
public Opportunity OppDetail { get; set; }
public List<SelectOption> contactRoles { get; set; }
public Contact_Role__c crc;
public String selectedContactRole { get; set; }
public Contact contactDetail { get; set; }
public List<Contact_Role__c> oppRoles { get; set; }
public boolean crcAvailable { get; set; }
public SetToWonController() {
OpportunityId = ApexPages.currentPage().getParameters().get('OpportunityId');
OppDetail = new Opportunity();
contactDetail = new Contact();
if( OpportunityId != null ){
OppDetail = [
SELECT Name,
Client_Delivery_Cut_Off__c,
Purchase_Order_Date__c,
Accredo_date_required__c,
Has_Accredo_fields_been_updated__c,
StageName,
Type
FROM Opportunity
WHERE Id = :OpportunityId
];
GetContactRoles();
}
}
public PageReference save() {
OppDetail.StageName = 'Project Management';
UPDATE OppDetail;
List<Contact_Role__c>crcList = new List<Contact_Role__c>();
if(selectedContactRole != '' && selectedContactRole != 'null'){
List<Contact_Role__c> crcOld = [ SELECT Id, Payment_Contact__c from Contact_Role__c where Payment_Contact__c = true AND Opportunity__c = :OppDetail.Id ];
if(crcOld.size() > 0) {
if(crcOld[0].Id != selectedContactRole) {
crcOld[0].Payment_Contact__c = false;
crcList.add( crcOld[0] );
}
}
Contact_Role__c crc = new Contact_Role__c();
crc.Payment_Contact__c = true;
crc.Id = selectedContactRole;
crcList.add( crc );
if(crcList.size() > 0){
update crcList;
}
if(String.isNotBlank(contactDetail.Email)){
Contact_Role__c cr = [ SELECT Contact__r.Id,Contact__r.Email from Contact_Role__c where id = :selectedContactRole ];
contactDetail.Id = cr.Contact__r.Id;
update contactDetail;
}
}
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Opp_Won_Email_Setting__c ows = Opp_Won_Email_Setting__c.getInstance( 'Won Email' );
List<String> sendTo = new List<String>();
sendTo.add(ows.Email__c);
if(!Test.isRunningTest()){
OrgWideEmailAddress owe = [SELECT ID,IsAllowAllProfiles,DisplayName,Address FROM OrgWideEmailAddress LIMIT 1];
mail.setOrgWideEmailAddressId(owe.Id);
}
mail.setToAddresses( sendTo );
mail.setSubject( 'Opportunity Won' );
String body = 'The Opportunity ' + OppDetail.Name + ', ';
body += '';
body += 'stage is set to Project Management';
mail.setHtmlBody( body );
mails.add(mail);
Messaging.sendEmail(mails);
return null;
}
public void closePopup(){
Opportunity_Tab_Controller otc = new Opportunity_Tab_Controller();
otc.closePopup();
}
public List<SelectOption> GetContactRoles() {
oppRoles = new List<Contact_Role__c>();
contactRoles = new List<SelectOption>();
oppRoles = [ SELECT Id, Name, Contact__r.Name, Contact__r.Email, Contact__r.Id, Payment_Contact__c from Contact_Role__c where Opportunity__c = :OpportunityId ];
if(oppRoles.size() == 0) {
crcAvailable = false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Contact Role Does not exists,Please add Contact Role and Try again'));
return null;
}
else{
crcAvailable = true;
}
for(Contact_Role__c cr : oppRoles){
contactRoles.add(new SelectOption(cr.Id,cr.Contact__r.Name));
//if(cr.Payment_Contact__c == true){
selectedContactRole = cr.Id;
contactDetail.Email = cr.Contact__r.Email;
//}
}
return contactRoles;
}
public void CheckContactRoles(){
Contact_Role__c conRoles = new Contact_Role__c();
conRoles = [ SELECT Contact__r.Id, Contact__r.Email from Contact_Role__c where id = :selectedContactRole ];
contactDetail.Email = conRoles.Contact__r.Email;
}
}
Thanks In Advance,
Pavan Vempati.
Please Explain in a detailed manner,So that I can resolve the issue
Thanks & Regards,
Pavan Vempati.
The error seems to be coming in line 64 as shown in screenshot.
This is due to either custom setting (Opp_Won_Email_Setting__c) being null or its Email__c field being null.
You need to apply this check on line 64 as shown :
if(ows.Email__c != null){
sendTo.add(ows.Email__c);
}
Mark as solve if this resolves the issue.
Thanx
Medhya
Whenever you click the save button on the VF page set_to_won the mehtod save() gets called.
This method looks for a custom setting named Opp_Won_Email_Setting__c ( go to setup--> custom settings) and find the setting there.
There seems to be no value present for feld Email__c for the value 'Won Email'.( go to setup--> custom settings-->Manage---.>)find the option that has Name = 'Won Email' by cliking on edit, update its Email__c field).
See Link for reference : http://blog.jeffdouglas.com/2010/01/07/using-list-custom-settings-in-salesforce-com/
Updating the custom setting might do the trick, however it's better to apply the check in the class to avoid such error in future.
Regards
Medhya