-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
11Questions
-
25Replies
Visualforce page : Export Results to Excel or CSV
I have created a VF page which fetch the records from object based on the critirea selected by user. Based the critirea I have created a results section in VF page which shows all the relevant information. I have added a custom button " export to excel". Whenever users click this button , it should export all the RESULTS to excel. In order to achieve this , I have created a 2nd VF page same as my original page but with "contentype " attribute. When i click the button , It is exporting the results but It is also exporting the some irrelevant data .
VF Page:
<apex:page controller="Fetchsiteplacement12" tabStyle="Site_Placements__c" sidebar="True" contentType="application/vnd.ms-excel#filename.xls" language="en-US" cache="True">
<apex:form >
<apex:pageBlock >
<apex:messages />
<apex:pageBlockButtons location="Both">
<apex:commandButton value="Fetch" action="{!FetchSPRec}"/>
<apex:commandButton value="Cancel" action="{!CancelSPRec}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Results">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!spRec}" var="site" columnsWidth="500px, 500px" >
<apex:column value="{!se.Name}"/>
<apex:column value="{!se.Placement__c}"/>
<apex:column value="{!se.Level_Max__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
APex class:
And, in the apex class , I am using this :
public PageReference FetchExcelReport() {
PageReference nextpage = new PageReference('/apex/ExcelReportPage');
return nextpage;
}
Below is irrelevent info:
if(!window.sfdcPage){window.sfdcPage = new ApexDetailPage();} UserContext.initialize({"networkId":"","locale":"en_US","labelLastModified":"1393912808000","isDefaultNetwork":true,"today":"3/5/2014 4:23 PM","timeFormat":"h:mm a","userPreferences":[{"index":112,"name":"HideInlineEditSplash","value":false},{"index":114,"name":"OverrideTaskSendNotification","value":false},{"index":115,"name":"DefaultTaskSendNotification","value":false},{"index":119,"name":"HideUserLayoutStdFieldInfo","value":false},{"index":116,"name":"HideRPPWarning","value":false},{"index":87,"name":"HideInlineSchedulingSplash","value":false},{"index":88,"name":"HideCRUCNotification","value":false},{"index":89,"name":"HideNewPLESplash","value":false},{"index":90,"name":"HideNewPLEWarnIE6","value":false},{"index":122,"name":"HideOverrideSharingMessage","value":false},{"index":91,"name":"HideProfileILEWarn","value":false},{"index":93,"name":"HideProfileElvVideo","value":false},{"index":97,"name":"ShowPicklistEditSplash","value":false},{"index":92,"name":"HideDataCategorySplash","value":false},{"index":128,"name":"ShowDealView","value":false},{"index":129,"name":"HideDealViewGuidedTour","value":false},{"index":132,"name":"HideKnowledgeFirstTimeSetupMsg","value":false},{"index":104,"name":"DefaultOffEntityPermsMsg","value":false},{"index":135,"name":"HideNewCsnSplash","value":false},{"index":101,"name":"HideBrowserWarning","value":false},{"index":139,"name":"HideDashboardBuilderGuidedTour","value":false},{"index":140,"name":"HideSchedulingGuidedTour","value":false},{"index":180,"name":"HideReportBuilderGuidedTour","value":true},{"index":183,"name":"HideAssociationQueueCallout","value":false},{"index":194,"name":"HideQTEBanner","value":false},{"index":193,"name":"HideChatterOnboardingSplash","value":true},{"index":195,"name":"HideSecondChatterOnboardingSplash","value":true},{"index":270,"name":"HideIDEGuidedTour","value":true},{"index":282,"name":"HideQueryToolGuidedTour","value":false},{"index":196,"name":"HideCSIGuidedTour","value":true},{"index":271,"name":"HideFewmetGuidedTour","value":false},{"index":272,"name":"HideEditorGuidedTour","value":true},{"index":205,"name":"HideApexTestGuidedTour","value":false},{"index":206,"name":"HideSetupProfileHeaderTour","value":true},{"index":207,"name":"HideSetupProfileObjectsAndTabsTour","value":true},{"index":213,"name":"DefaultOffArticleTypeEntityPermMsg","value":false},{"index":214,"name":"HideSelfInfluenceGetStarted","value":false},{"index":215,"name":"HideOtherInfluenceGetStarted","value":false},{"index":216,"name":"HideFeedToggleGuidedTour","value":false},{"index":268,"name":"ShowChatterTab178GuidedTour","value":false},{"index":275,"name":"HidePeopleTabDeprecationMsg","value":false},{"index":276,"name":"HideGroupTabDeprecationMsg","value":false},{"index":222,"name":"TouchExternalLinkReminderSuppression","value":false},{"index":224,"name":"HideUnifiedSearchGuidedTour","value":true},{"index":226,"name":"ShowDevContextMenu","value":true},{"index":227,"name":"HideWhatRecommenderForActivityQueues","value":false},{"index":228,"name":"HideLiveAgentFirstTimeSetupMsg","value":false},{"index":232,"name":"HideGroupAllowsGuestsMsgOnMemberWidget","value":false},{"index":233,"name":"HideGroupAllowsGuestsMsg","value":false},{"index":234,"name":"HideWhatAreGuestsMsg","value":false},{"index":235,"name":"HideNowAllowGuestsMsg","value":false},{"index":236,"name":"HideSocialAccountsAndContactsGuidedTour","value":false},{"index":237,"name":"HideAnalyticsHomeGuidedTour","value":true},{"index":238,"name":"ShowQuickCreateGuidedTour","value":false},{"index":245,"name":"HideFilePageGuidedTour","value":false},{"index":250,"name":"HideForecastingGuidedTour","value":false},{"index":242,"name":"TouchHideOptoutHover","value":false},{"index":251,"name":"HideBucketFieldGuide","value":false},{"index":263,"name":"HideSmartSearchCallOut","value":true},{"index":265,"name":"HideSocialProfilesKloutSplashScreen","value":false},{"index":273,"name":"ShowForecastingQuotaAttainment","value":false},{"index":280,"name":"HideForecastingQuotaColumn","value":false},{"index":301,"name":"HideManyWhoGuidedTour","value":false},{"index":284,"name":"HideExternalSharingModelGuidedTour","value":false},{"index":298,"name":"HideFileSyncBannerMsg","value":false},{"index":299,"name":"HideTestConsoleGuidedTour","value":true},{"index":300,"name":"HideNetworkSetupOverlayGettingStarted","value":false},{"index":302,"name":"HideManyWhoInlineEditTip","value":false},{"index":303,"name":"HideSetupV2WelcomeMessage","value":false},{"index":312,"name":"ForecastingShowQuantity","value":false},{"index":313,"name":"HideDataImporterIntroMsg","value":false},{"index":314,"name":"HideEnvironmentHubLightbox","value":false},{"index":316,"name":"HideSetupV2GuidedTour","value":false},{"index":317,"name":"HideFileSyncMobileDownloadDialog","value":false},{"index":318,"name":"HideHelpBannerQuickActionList","value":false},{"index":321,"name":"HideCustomEntityQuickActionCallout","value":true},{"index":322,"name":"HideEnhancedProfileHelpBubble","value":false},{"index":328,"name":"ForecastingHideZeroRows","value":false},{"index":330,"name":"HideEmbeddedComponentsFeatureCallout","value":true},{"index":340,"name":"HideS1BrowserUI","value":false}],"orgPreferences":[{"index":257,"name":"TabOrganizer","value":true}],"startOfWeek":"1","isAccessibleMode":false,"ampm":["AM","PM"],"renderMode":"RETRO","userId":"00570000002Nayk","dateTimeFormat":"M/d/yyyy h:mm a","dateFormat":"M/d/yyyy","uiSkin":"Theme3","language":"en_US","siteUrlPrefix":""});
function twistSection(twisty, sectionId) { var parentDiv = twisty; while (parentDiv.tagName != 'DIV') { parentDiv = parentDiv.parentNode; } var div = parentDiv.nextSibling; var elemWasOn = false; if (div.style.display != 'none') { div.style.display = 'none'; twisty.className ='showListButton'; twisty.alt = twisty.title = 'Show Section - '+twisty.name; elemWasOn = true; } else { div.style.display = 'block'; twisty.className = 'hideListButton'; twisty.alt = twisty.title = 'Hide Section - '+twisty.name; } return !elemWasOn; } var registeredSections = new Array(); function registerTwistableSection(headerId, mainTableId) { var obj = new Object(); obj.headerId = headerId; obj.mainTableId = mainTableId; registeredSections[registeredSections.length] = obj; } function twistAllSections(on) { for (var i = 0; i < registeredSections.length; i++) { var obj = registeredSections[i]; var img; img = document.getElementById('img_' + obj.headerId); if (on && 'showListButton' == img.className) { twistSection(img, obj.headerId, obj.mainTableId); } else if (!on && 'hideListButton' == img.className) { twistSection(img, obj.headerId, obj.mainTableId); } } } function toggleSection(headerId, on){ var sectionHead = document.getElementById('head_'+headerId+'_j_id0_j_id1_j_id2'); var body = sectionHead.nextSibling; var disp = on ? 'block' : 'none'; sectionHead.style.display = disp; body.style.display = disp; } function registerTwistableSections_j_id0_j_id1_j_id2() { registerTwistableSection('j_id0_j_id1_j_id2_j_id7', 'j_id0_j_id1_j_id2'); registerTwistableSection('j_id0_j_id1_j_id2_j_id22', 'j_id0_j_id1_j_id2'); registerTwistableSection('j_id0_j_id1_j_id2_j_id27', 'j_id0_j_id1_j_id2'); } registerTwistableSections_j_id0_j_id1_j_id2();
Kindly help me.
- devsalesforce27
- March 06, 2014
- Like
- 0
Please help : <apex:inputField> can only be used with SObjects
Hi All,
I am creating a single entry form page of opportunities and cuboid__c. Cuboid__c has a lookup relation to opportunities. I want one page which comprises of fields from both the objects. I have created a visulforce page but I am getting this error.
Error: Could not resolve the entity from <apex:inputField> value binding '{!Opp.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
<apex:page id="page" Controller="newopportunitycontroller">
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!save}" value="save"/>
<apex:commandButton action="{!cancel}" value="cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information" collapsible="true" columns="1" >
<apex:pageBlockSectionItem id="accountSectionItem">
<apex:outputLabel id="OpportunityNameLabel" for="opportunityName" value="Opportunity Name" />
<apex:inputField id="OpportunityName" value="{!Opp.Name}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="schedules and actuals" collapsible="true">
<apex:pageBlockSectionItem id="contactFirstNameSectionItem">
<apex:outputLabel id="cuboidheight" for="cuboiddheight" value="Height" />
<apex:inputField id="cuboidddheight" value="{!cub.height__c}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Below is the apex class which is also giving this error:
Didn't understand relationship 'Opportunity__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 15
- devsalesforce27
- October 17, 2013
- Like
- 0
Urgent: Webservice callout
Hey guys,
I have developed a basic VF page which is basically a general form entry page for end user. We will be placing this page on force.com Site. we want whenevr users click the submit button, two tasks should be performed.
1.) Record should be saved in Lead.
2.) all the information enetered in the fields should be sent to SAP.
In order to send information to SAP, I have generated apex class from WSDL (provided by SAP). Now next step is to callout this webservice class in the submit button. I have idea how to do this . I would really aprreciate if somone can guide me. below is the generated apex class.
//Generated by wsdl2apex
public class sapComDocumentSapRfcFunctions {
public class ZARU_S_ATHENA_EVAL_ORDER {
public String FIRST_NAME;
public String LAST_NAME;
public String COMPANY;
public String EMAIL_ADDRESS;
public String TELEPHONE;
public String CITY;
public String COUNTRY;
public String POSTAL_CODE;
public String CAMPAIGN;
public String USER_TYPE;
public String EVALUATION_HORIZON;
public String POTENTIAL_USER_COUNT;
public String EVALUATION_TERMS;
private String[] FIRST_NAME_type_info = new String[]{'FIRST_NAME','urn:sap-com:document:sap:rfc:functions','char60','1','1','false'};
private String[] LAST_NAME_type_info = new String[]{'LAST_NAME','urn:sap-com:document:sap:rfc:functions','char60','1','1','false'};
private String[] COMPANY_type_info = new String[]{'COMPANY','urn:sap-com:document:sap:rfc:functions','char50','1','1','false'};
private String[] EMAIL_ADDRESS_type_info = new String[]{'EMAIL_ADDRESS','urn:sap-com:document:sap:rfc:functions','char241','1','1','false'};
private String[] TELEPHONE_type_info = new String[]{'TELEPHONE','urn:sap-com:document:sap:rfc:functions','char30','1','1','false'};
private String[] CITY_type_info = new String[]{'CITY','urn:sap-com:document:sap:rfc:functions','char35','1','1','false'};
private String[] COUNTRY_type_info = new String[]{'COUNTRY','urn:sap-com:document:sap:rfc:functions','char3','1','1','false'};
private String[] POSTAL_CODE_type_info = new String[]{'POSTAL_CODE','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
private String[] CAMPAIGN_type_info = new String[]{'CAMPAIGN','urn:sap-com:document:sap:rfc:functions','char80','1','1','false'};
private String[] USER_TYPE_type_info = new String[]{'USER_TYPE','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
private String[] EVALUATION_HORIZON_type_info = new String[]{'EVALUATION_HORIZON','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
private String[] POTENTIAL_USER_COUNT_type_info = new String[]{'POTENTIAL_USER_COUNT','urn:sap-com:document:sap:rfc:functions','numeric5','1','1','false'};
private String[] EVALUATION_TERMS_type_info = new String[]{'EVALUATION_TERMS','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:rfc:functions','false','true'};
private String[] field_order_type_info = new String[]{'FIRST_NAME','LAST_NAME','COMPANY','EMAIL_ADDRESS','TELEPHONE','CITY','COUNTRY','POSTAL_CODE','CAMPAIGN','USER_TYPE','EVALUATION_HORIZON','POTENTIAL_USER_COUNT','EVALUATION_TERMS'};
}
public class Z_ATHENA_EVAL_ORDERSoapBinding {
public String endpoint_x = 'http://DEC.arubanetworks.com:8000/sap/bc/srt/rfc/sap/Z_ATHENA_EVAL_ORDER?sap-client=500';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'urn:sap-com:document:sap:rfc:functions', 'sapComDocumentSapRfcFunctions'};
public sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element ZARU_BAPI_CREATE_EVAL_ORDER(sapComDocumentSapRfcFunctions.BAPIRET2_TT ET_RETURN,String I_DEFAULT_VALUES_KEY,sapComDocumentSapRfcFunctions.ZARU_S_ATHENA_EVAL_ORDER I_EVAL_ORDER,String I_TESTRUN) {
sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDER_element request_x = new sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDER_element();
sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element response_x;
request_x.ET_RETURN = ET_RETURN;
request_x.I_DEFAULT_VALUES_KEY = I_DEFAULT_VALUES_KEY;
request_x.I_EVAL_ORDER = I_EVAL_ORDER;
request_x.I_TESTRUN = I_TESTRUN;
Map<String, sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element> response_map_x = new Map<String, sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://DEC.arubanetworks.com:8000/sap/bc/srt/rfc/sap/Z_ATHENA_EVAL_ORDER?sap-client=500',
'urn:sap-com:document:sap:rfc:functions',
'ZARU_BAPI_CREATE_EVAL_ORDER',
'urn:sap-com:document:sap:rfc:functions',
'ZARU_BAPI_CREATE_EVAL_ORDERResponse',
'sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x;
}
}
public class ZARU_BAPI_CREATE_EVAL_ORDER_element {
public sapComDocumentSapRfcFunctions.BAPIRET2_TT ET_RETURN;
public String I_DEFAULT_VALUES_KEY;
public sapComDocumentSapRfcFunctions.ZARU_S_ATHENA_EVAL_ORDER I_EVAL_ORDER;
public String I_TESTRUN;
private String[] ET_RETURN_type_info = new String[]{'ET_RETURN','urn:sap-com:document:sap:rfc:functions','BAPIRET2_TT','1','1','false'};
private String[] I_DEFAULT_VALUES_KEY_type_info = new String[]{'I_DEFAULT_VALUES_KEY','urn:sap-com:document:sap:rfc:functions','char4','0','1','false'};
private String[] I_EVAL_ORDER_type_info = new String[]{'I_EVAL_ORDER','urn:sap-com:document:sap:rfc:functions','ZARU_S_ATHENA_EVAL_ORDER','1','1','false'};
private String[] I_TESTRUN_type_info = new String[]{'I_TESTRUN','urn:sap-com:document:sap:rfc:functions','char1','0','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:rfc:functions','false','true'};
private String[] field_order_type_info = new String[]{'ET_RETURN','I_DEFAULT_VALUES_KEY','I_EVAL_ORDER','I_TESTRUN'};
}
- devsalesforce27
- September 06, 2013
- Like
- 0
Urgent: Apex Trigger not updating Look up field
Hey ,
I have a situation in which whenever a TASK is created , it should automatically create a new record in custom object ( XYZ__C) by taking values from the custom fields in TASK object. Custom objec(XYZ__C) has 3 fields , 2 picklists and one is lookup field. My trigger is fetching the values for picklists but it is not fetching for lookup field. Its is giving the below error. Trigger is also mentioned below . I have checked all the previous threads also. Anyone who can fix the below code would be great
Apex trigger createleadinterest caused an unexpected exception, contact your administrator: createleadinterest: execution of AfterUpdate caused by: System.StringException: Invalid id: 2012 Fall: Trigger.createleadinterest: line 13, column 1
trigger createleadinterest on Task (after insert,after update) {
List <XYZ__c> leadinterest = new List <XYZ__c>();
for (Task tk : Trigger.new) {
if (tk.Type == 'Web Form') {
XYZ__c ld = new XYZ__c (); //instantiate the object to put values for future record
ld.Primary_Source__c = tk.Task_Source__c; // and so on so forth untill you map all the fields.
ld.Term__c = tk.Enrollment_Term__c; // Term__c is a look up field on XYZ__c
leadinterest.add(ld);
}
}
try {
insert leadinterest;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
- devsalesforce27
- June 06, 2013
- Like
- 0
urgent: validation rules help
Hey,
I have a situation in which I have particular number of codes in a single record in an object(object1__c). I have another object (object2__c)which have the same codes and all these codes are associated with a single key value. I want when a user selects the set of codes from object1__c , it should match look up to codes which are already present in object2__c and validate that there is a particular key value associated with these set of codes. If not , it should give an error. Any little help will be highly appreciated.
Regards
- devsalesforce27
- May 29, 2013
- Like
- 0
URGENT: validation rules help
Hey,
I have a situation in which I have particular number of codes in a single record in an object(object1__c). I have another object (object2__c)which have the same codes and all these codes are associated with a single key value. I want when a user selects the set of codes from object1__c , it should match look up to codes which are already present in object2__c and validate that there is a particular key value associated with these set of codes. If not , it should give an error. Any little help will be highly appreciated.
Regards
- devsalesforce27
- May 29, 2013
- Like
- 0
Help: Trigger not executing automatic approval process
Hi,
I want whenever the user enters the recods from web to lead process. It should automatically be submitted to worflow approvals. I have written a trigger , mentioned below. When I create a new record , it is giving this error: I am not getting why this error is coming.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger leadApprovalSubmit caused an unexpected exception, contact your administrator: leadApprovalSubmit: execution of BeforeInsert caused by: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: []: Trigger.leadApprovalSubmit: line 15, column 1
trigger leadApprovalSubmit on Lead (before insert) {
for (Lead l : trigger.new) {
// Create an approval request for the lead
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(l.id);
// Submit the approval request for the lead
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
}
}
Ps- error is same with after insert also. Pls help
- devsalesforce27
- March 28, 2013
- Like
- 0
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);
}
}
- devsalesforce27
- March 08, 2013
- Like
- 0
Help:Display Error on visualforce page depending upon checkbox
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);
}
}
- devsalesforce27
- March 07, 2013
- Like
- 0
execute custom button through javascript
Hey All ,
I have created a custom button to send the user record for approval. This button is working fine when it is pressed first time. I want that when it is pressed again it should give an alert message "User record already in approval process". I know it is very easy but I am new to programming so pls help out in this.apex class and javascript is below:-
Apex class:
global class SAPRequest1 {
WebService static void SendApprovalRequest(Id AccountId ) {
// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
req.setObjectId(AccountId);
// submit the approval request for processing
Approval.ProcessResult result = Approval.Process(req);
// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());
}
}
Javascript:
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
sforce.apex.execute("SAPRequest","SendApprovalRequest", {id:"{!Account.Id}"});
window.alert("Record sent for approval" );
- devsalesforce27
- March 04, 2013
- Like
- 0
Urgent: Approval process through javascript (custom button)
Hey All ,
We are using SAP as our ERP . I have created a custom button in salesforce.com on Account Record namely , "SAPRequest" . Whenever user clicks on this button, record should be submitted for approval (WE DONT CARE ABOUT THE APPROVERS , IT SHOULD JUST BE SUBITTED FOR APPROVAL ) . I created a apex class and javascript for this below:
Apex class:
global class SAPRequest {
WebService static void SendApprovalRequest(string id) {
// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
// submit the approval request for processing
Approval.ProcessResult result = Approval.Process(req);
// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());
}
}
Javascript:
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
sforce.apex.execute("SAPRequest","SendApprovalRequest", {id:"{!Account.Id}"});
window.alert("Record sent for approval" );
But when I click the SAPRequest Button , I get this error in dialogue box:
A problem with OnClick JavaScript for this button or link was encountered:
{faultcode:'soapenv:client',
faultstring:'System.DMLException:Process failed.First
exception on row 0,first error :REQUIRED_FIELD_MISSING,
missing required field;[]
class.SAPRequest.SendApprovalRequest: line 9, column 1',}
Please help me in fixing this . I will really be grateful to you guys..
Regards
- devsalesforce27
- February 27, 2013
- Like
- 0
Visualforce page : Export Results to Excel or CSV
I have created a VF page which fetch the records from object based on the critirea selected by user. Based the critirea I have created a results section in VF page which shows all the relevant information. I have added a custom button " export to excel". Whenever users click this button , it should export all the RESULTS to excel. In order to achieve this , I have created a 2nd VF page same as my original page but with "contentype " attribute. When i click the button , It is exporting the results but It is also exporting the some irrelevant data .
VF Page:
<apex:page controller="Fetchsiteplacement12" tabStyle="Site_Placements__c" sidebar="True" contentType="application/vnd.ms-excel#filename.xls" language="en-US" cache="True">
<apex:form >
<apex:pageBlock >
<apex:messages />
<apex:pageBlockButtons location="Both">
<apex:commandButton value="Fetch" action="{!FetchSPRec}"/>
<apex:commandButton value="Cancel" action="{!CancelSPRec}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Results">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!spRec}" var="site" columnsWidth="500px, 500px" >
<apex:column value="{!se.Name}"/>
<apex:column value="{!se.Placement__c}"/>
<apex:column value="{!se.Level_Max__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
APex class:
And, in the apex class , I am using this :
public PageReference FetchExcelReport() {
PageReference nextpage = new PageReference('/apex/ExcelReportPage');
return nextpage;
}
Below is irrelevent info:
if(!window.sfdcPage){window.sfdcPage = new ApexDetailPage();} UserContext.initialize({"networkId":"","locale":"en_US","labelLastModified":"1393912808000","isDefaultNetwork":true,"today":"3/5/2014 4:23 PM","timeFormat":"h:mm a","userPreferences":[{"index":112,"name":"HideInlineEditSplash","value":false},{"index":114,"name":"OverrideTaskSendNotification","value":false},{"index":115,"name":"DefaultTaskSendNotification","value":false},{"index":119,"name":"HideUserLayoutStdFieldInfo","value":false},{"index":116,"name":"HideRPPWarning","value":false},{"index":87,"name":"HideInlineSchedulingSplash","value":false},{"index":88,"name":"HideCRUCNotification","value":false},{"index":89,"name":"HideNewPLESplash","value":false},{"index":90,"name":"HideNewPLEWarnIE6","value":false},{"index":122,"name":"HideOverrideSharingMessage","value":false},{"index":91,"name":"HideProfileILEWarn","value":false},{"index":93,"name":"HideProfileElvVideo","value":false},{"index":97,"name":"ShowPicklistEditSplash","value":false},{"index":92,"name":"HideDataCategorySplash","value":false},{"index":128,"name":"ShowDealView","value":false},{"index":129,"name":"HideDealViewGuidedTour","value":false},{"index":132,"name":"HideKnowledgeFirstTimeSetupMsg","value":false},{"index":104,"name":"DefaultOffEntityPermsMsg","value":false},{"index":135,"name":"HideNewCsnSplash","value":false},{"index":101,"name":"HideBrowserWarning","value":false},{"index":139,"name":"HideDashboardBuilderGuidedTour","value":false},{"index":140,"name":"HideSchedulingGuidedTour","value":false},{"index":180,"name":"HideReportBuilderGuidedTour","value":true},{"index":183,"name":"HideAssociationQueueCallout","value":false},{"index":194,"name":"HideQTEBanner","value":false},{"index":193,"name":"HideChatterOnboardingSplash","value":true},{"index":195,"name":"HideSecondChatterOnboardingSplash","value":true},{"index":270,"name":"HideIDEGuidedTour","value":true},{"index":282,"name":"HideQueryToolGuidedTour","value":false},{"index":196,"name":"HideCSIGuidedTour","value":true},{"index":271,"name":"HideFewmetGuidedTour","value":false},{"index":272,"name":"HideEditorGuidedTour","value":true},{"index":205,"name":"HideApexTestGuidedTour","value":false},{"index":206,"name":"HideSetupProfileHeaderTour","value":true},{"index":207,"name":"HideSetupProfileObjectsAndTabsTour","value":true},{"index":213,"name":"DefaultOffArticleTypeEntityPermMsg","value":false},{"index":214,"name":"HideSelfInfluenceGetStarted","value":false},{"index":215,"name":"HideOtherInfluenceGetStarted","value":false},{"index":216,"name":"HideFeedToggleGuidedTour","value":false},{"index":268,"name":"ShowChatterTab178GuidedTour","value":false},{"index":275,"name":"HidePeopleTabDeprecationMsg","value":false},{"index":276,"name":"HideGroupTabDeprecationMsg","value":false},{"index":222,"name":"TouchExternalLinkReminderSuppression","value":false},{"index":224,"name":"HideUnifiedSearchGuidedTour","value":true},{"index":226,"name":"ShowDevContextMenu","value":true},{"index":227,"name":"HideWhatRecommenderForActivityQueues","value":false},{"index":228,"name":"HideLiveAgentFirstTimeSetupMsg","value":false},{"index":232,"name":"HideGroupAllowsGuestsMsgOnMemberWidget","value":false},{"index":233,"name":"HideGroupAllowsGuestsMsg","value":false},{"index":234,"name":"HideWhatAreGuestsMsg","value":false},{"index":235,"name":"HideNowAllowGuestsMsg","value":false},{"index":236,"name":"HideSocialAccountsAndContactsGuidedTour","value":false},{"index":237,"name":"HideAnalyticsHomeGuidedTour","value":true},{"index":238,"name":"ShowQuickCreateGuidedTour","value":false},{"index":245,"name":"HideFilePageGuidedTour","value":false},{"index":250,"name":"HideForecastingGuidedTour","value":false},{"index":242,"name":"TouchHideOptoutHover","value":false},{"index":251,"name":"HideBucketFieldGuide","value":false},{"index":263,"name":"HideSmartSearchCallOut","value":true},{"index":265,"name":"HideSocialProfilesKloutSplashScreen","value":false},{"index":273,"name":"ShowForecastingQuotaAttainment","value":false},{"index":280,"name":"HideForecastingQuotaColumn","value":false},{"index":301,"name":"HideManyWhoGuidedTour","value":false},{"index":284,"name":"HideExternalSharingModelGuidedTour","value":false},{"index":298,"name":"HideFileSyncBannerMsg","value":false},{"index":299,"name":"HideTestConsoleGuidedTour","value":true},{"index":300,"name":"HideNetworkSetupOverlayGettingStarted","value":false},{"index":302,"name":"HideManyWhoInlineEditTip","value":false},{"index":303,"name":"HideSetupV2WelcomeMessage","value":false},{"index":312,"name":"ForecastingShowQuantity","value":false},{"index":313,"name":"HideDataImporterIntroMsg","value":false},{"index":314,"name":"HideEnvironmentHubLightbox","value":false},{"index":316,"name":"HideSetupV2GuidedTour","value":false},{"index":317,"name":"HideFileSyncMobileDownloadDialog","value":false},{"index":318,"name":"HideHelpBannerQuickActionList","value":false},{"index":321,"name":"HideCustomEntityQuickActionCallout","value":true},{"index":322,"name":"HideEnhancedProfileHelpBubble","value":false},{"index":328,"name":"ForecastingHideZeroRows","value":false},{"index":330,"name":"HideEmbeddedComponentsFeatureCallout","value":true},{"index":340,"name":"HideS1BrowserUI","value":false}],"orgPreferences":[{"index":257,"name":"TabOrganizer","value":true}],"startOfWeek":"1","isAccessibleMode":false,"ampm":["AM","PM"],"renderMode":"RETRO","userId":"00570000002Nayk","dateTimeFormat":"M/d/yyyy h:mm a","dateFormat":"M/d/yyyy","uiSkin":"Theme3","language":"en_US","siteUrlPrefix":""});
function twistSection(twisty, sectionId) { var parentDiv = twisty; while (parentDiv.tagName != 'DIV') { parentDiv = parentDiv.parentNode; } var div = parentDiv.nextSibling; var elemWasOn = false; if (div.style.display != 'none') { div.style.display = 'none'; twisty.className ='showListButton'; twisty.alt = twisty.title = 'Show Section - '+twisty.name; elemWasOn = true; } else { div.style.display = 'block'; twisty.className = 'hideListButton'; twisty.alt = twisty.title = 'Hide Section - '+twisty.name; } return !elemWasOn; } var registeredSections = new Array(); function registerTwistableSection(headerId, mainTableId) { var obj = new Object(); obj.headerId = headerId; obj.mainTableId = mainTableId; registeredSections[registeredSections.length] = obj; } function twistAllSections(on) { for (var i = 0; i < registeredSections.length; i++) { var obj = registeredSections[i]; var img; img = document.getElementById('img_' + obj.headerId); if (on && 'showListButton' == img.className) { twistSection(img, obj.headerId, obj.mainTableId); } else if (!on && 'hideListButton' == img.className) { twistSection(img, obj.headerId, obj.mainTableId); } } } function toggleSection(headerId, on){ var sectionHead = document.getElementById('head_'+headerId+'_j_id0_j_id1_j_id2'); var body = sectionHead.nextSibling; var disp = on ? 'block' : 'none'; sectionHead.style.display = disp; body.style.display = disp; } function registerTwistableSections_j_id0_j_id1_j_id2() { registerTwistableSection('j_id0_j_id1_j_id2_j_id7', 'j_id0_j_id1_j_id2'); registerTwistableSection('j_id0_j_id1_j_id2_j_id22', 'j_id0_j_id1_j_id2'); registerTwistableSection('j_id0_j_id1_j_id2_j_id27', 'j_id0_j_id1_j_id2'); } registerTwistableSections_j_id0_j_id1_j_id2();
Kindly help me.
- devsalesforce27
- March 06, 2014
- Like
- 0
Please help : <apex:inputField> can only be used with SObjects
Hi All,
I am creating a single entry form page of opportunities and cuboid__c. Cuboid__c has a lookup relation to opportunities. I want one page which comprises of fields from both the objects. I have created a visulforce page but I am getting this error.
Error: Could not resolve the entity from <apex:inputField> value binding '{!Opp.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
<apex:page id="page" Controller="newopportunitycontroller">
<apex:form >
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!save}" value="save"/>
<apex:commandButton action="{!cancel}" value="cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information" collapsible="true" columns="1" >
<apex:pageBlockSectionItem id="accountSectionItem">
<apex:outputLabel id="OpportunityNameLabel" for="opportunityName" value="Opportunity Name" />
<apex:inputField id="OpportunityName" value="{!Opp.Name}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="schedules and actuals" collapsible="true">
<apex:pageBlockSectionItem id="contactFirstNameSectionItem">
<apex:outputLabel id="cuboidheight" for="cuboiddheight" value="Height" />
<apex:inputField id="cuboidddheight" value="{!cub.height__c}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Below is the apex class which is also giving this error:
Didn't understand relationship 'Opportunity__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 15
- devsalesforce27
- October 17, 2013
- Like
- 0
Urgent: Apex Trigger not updating Look up field
Hey ,
I have a situation in which whenever a TASK is created , it should automatically create a new record in custom object ( XYZ__C) by taking values from the custom fields in TASK object. Custom objec(XYZ__C) has 3 fields , 2 picklists and one is lookup field. My trigger is fetching the values for picklists but it is not fetching for lookup field. Its is giving the below error. Trigger is also mentioned below . I have checked all the previous threads also. Anyone who can fix the below code would be great
Apex trigger createleadinterest caused an unexpected exception, contact your administrator: createleadinterest: execution of AfterUpdate caused by: System.StringException: Invalid id: 2012 Fall: Trigger.createleadinterest: line 13, column 1
trigger createleadinterest on Task (after insert,after update) {
List <XYZ__c> leadinterest = new List <XYZ__c>();
for (Task tk : Trigger.new) {
if (tk.Type == 'Web Form') {
XYZ__c ld = new XYZ__c (); //instantiate the object to put values for future record
ld.Primary_Source__c = tk.Task_Source__c; // and so on so forth untill you map all the fields.
ld.Term__c = tk.Enrollment_Term__c; // Term__c is a look up field on XYZ__c
leadinterest.add(ld);
}
}
try {
insert leadinterest;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
- devsalesforce27
- June 06, 2013
- Like
- 0
Help: Trigger not executing automatic approval process
Hi,
I want whenever the user enters the recods from web to lead process. It should automatically be submitted to worflow approvals. I have written a trigger , mentioned below. When I create a new record , it is giving this error: I am not getting why this error is coming.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger leadApprovalSubmit caused an unexpected exception, contact your administrator: leadApprovalSubmit: execution of BeforeInsert caused by: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: []: Trigger.leadApprovalSubmit: line 15, column 1
trigger leadApprovalSubmit on Lead (before insert) {
for (Lead l : trigger.new) {
// Create an approval request for the lead
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(l.id);
// Submit the approval request for the lead
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
}
}
Ps- error is same with after insert also. Pls help
- devsalesforce27
- March 28, 2013
- Like
- 0
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);
}
}
- devsalesforce27
- March 08, 2013
- Like
- 0