function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vepakvepak 

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;

}
}

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

I don't know what are you missing please try to save this

 

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 
 

try{

}
catch(System.DmlException ca)
{
System.debug('ERROR: Not able to create B2Bcase:'+ ca);
}
return result;
}
}

 let me know is it get saved.

All Answers

Shashikant SharmaShashikant Sharma

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.

vepakvepak

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;

Shashikant SharmaShashikant Sharma

I don't know what are you missing please try to save this

 

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 
 

try{

}
catch(System.DmlException ca)
{
System.debug('ERROR: Not able to create B2Bcase:'+ ca);
}
return result;
}
}

 let me know is it get saved.

This was selected as the best answer
vepakvepak

It worked,

 

I also inserted create case statements aswell and worked fine.

 

Seems strange, but anyhow thanks  a lot for your time.

Shashikant SharmaShashikant Sharma

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.

vepakvepak

Shashi,

 

I maked it as solution.

 

Once again thanks for your time.

 

Vamsi.