You need to sign in to do that
Don't have an account?

unable to create custom record form email services class
For the code below I'm getting error as
Error: Compile Error: Variable does not exist: insert newb2bCase at line 40 column 1
can someone help me.
global class processB2Bcasehandler implements Messaging.InboundEmailHandler {
string emailAddress;string fName;string lName;
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
// Captures the sender's email address emailAddress = envelope.fromAddress;
// Retrieves the sender's first and last names
fName = email.fromname.substring(0,email.fromname.indexOf(' '));
lName = email.fromname.substring(email.fromname.indexOf(' '));
// Creates a contact from the information retrieved from the inbound email
Contact mycontact = new Contact();
try{
mycontact.FirstName = fName;
mycontact.LastName = lName;
mycontact.Email = emailAddress;insert mycontact;}
catch(System.DmlException co)
{
System.debug('ERROR: Not able to create contact:'+ co);
}
// Creates the case
WPOSP__B2B_Case__c newb2bCase = new WPOSP__B2B_Case__c();
try{
newb2bCase.WPOSP__Case_Description__c = email.plainTextBody;
newb2bCase.WPOSP__Case_Subject__c = email.subject;
newb2bCase.WPOSP__Contact_email__c= emailAddress;
newb2bCase.WPOSP__Customer_Name__c=email.fromname;
insert newb2bCase;
}
catch(System.DmlException ca)
{
System.debug('ERROR: Not able to create B2Bcase:'+ ca);
}
return result;
}
}
I don't know what are you missing please try to save this
let me know is it get saved.
All Answers
I just saved the same in my org just changed object type WPOSP__B2B_Case__c to another object in my org. Could you provide some more info about the issue.
Thanks Sashi for your quick reply.
I also tried not to insert record into WPOSP__B2B_Case__c then I'm getting error as
Variable does not exist: return result;
I don't know what are you missing please try to save this
let me know is it get saved.
It worked,
I also inserted create case statements aswell and worked fine.
Seems strange, but anyhow thanks a lot for your time.
I think there must be some extra block { } , any ways happy to know your issue got resolved.
Please mark it as resolved so that others can also get benifitted from it.
Shashi,
I maked it as solution.
Once again thanks for your time.
Vamsi.