You need to sign in to do that
Don't have an account?
CharlieLang
Web to case
I am trying to replicated a web to case form in visualforce.
The page sits in a tab on a clients org and at the moment emails me the contents of a form. i have got everything coded so it emails me everything fine.
Now what i'm trying to do is exactly copy the salesforce generated web to case form and get the visualforce form to post the form to the address in the html generated form. Unfortulately i'm getting the following error
This is the code i'm using in the controller
public with sharing class CaseExtension { public Case mycase {get; set;} public User localUser {get; set;} public String route {get; set;} public CaseExtension(ApexPages.StandardController stdController) { this.mycase = (Case)stdController.getRecord(); localUser = [SELECT Id, Phone, Email, FirstName, LastName from User where Id =: System.UserInfo.getUserId() LIMIT 1]; this.mycase.OwnerId = localUser.Id; } public PageReference saveCase(){ try { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {'https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8'}; mail.setToAddresses(toAddresses); mail.setPlainTextBody('orgid=00DD0000000Cl9q' + '&retURL=VF_Evo1_Tab&name=' + localUser.FirstName + '&email=' + localUser.Email + '&phone=' + localUser.Phone + '&subject=' + mycase.Subject + '&description=' + mycase.Description + '&00ND0000002wUGd=' + route + '&external=1&submit=Submit' ); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } catch(System.DMLException e){ ApexPages.addMessages(e); return null; } // PageReference p = Page.ThankYou; // p.setRedirect(true); return null; } }
Just wondering if enyone could help me resolve this problem
Just wondering if anyone is able to help me with this?
Thanks in advance
Hi Charlie,
You can build a post using the httpRequest class instead:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm
Why are you trying to post to the Web-to-Case form instead of working directly with the Cases in Apex?
Vincent
Agreed, just write directly to the case object.
It's as simple as...
Hi Cirro,
Sorry for the delayed response - been abroad for the last few days.
Basically, the VF page that sits in a number of clients orgs and it pulls all their details from their user profile page and at the moment it sends it to me as an email. What i am wanting to do is use a form in say Company A's org to send a case to my company's org so the way i am trying to do it is by duplicating the web to case for in Visualforce and an Apex controller. I am pretty sure its the best way of going round things.
The last bit I am stumped with is the posting it into my org with the http request!
am i going along the right lines with this?
I'd appreciate any help with this...
Hi Charlie,
You need to start with an instance of Http, and send the request with the HttpRequest's send method. Building your request along the lines of the example on the page:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http.htm
should work for you.
Vincent