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
Krishnan01Krishnan01 

hello friends, help me out becoz "i am beginners in apex class"

"'this code is for the particular object, where based from received mail it has to be saved to account object"       //

Global class Accountcreationfrommail implements messaging.InboundEmailHandler {
    Global messaging.InboundEmailResult handleinboundemail(messaging.InboundEmail email,messaging.InboundEnvelope envelope) {
        messaging.InboundEmailResult a = new messaging.InboundEmailResult();
        String ename=email.fromName;
        String edescription=email.plainTextBody;
        String eindustry=email.subject;
        Account acc=new
            Account(name=ename,description=edescription,industry=eindustry);
        insert acc;
        return a;
    }
}



\\\  I dont want to mention any object  \\    "if I receive an email where by received mail Record has to be created and  it has to be associated to the particular object like   "if i mention in the email where it has to be saved to account object or if  i  mention Opportunity it has to created in opportunity" how can i write a program for this help me out........
Raj VakatiRaj Vakati
You can do it like .. If the Subject is contained an account then create an account otherwise create an opportunity. 

For Example 
 
Global class Accountcreationfrommail implements messaging.InboundEmailHandler {
    Global messaging.InboundEmailResult handleinboundemail(messaging.InboundEmail email,messaging.InboundEnvelope envelope) {
		
		
        messaging.InboundEmailResult a = new messaging.InboundEmailResult();
        String ename=email.fromName;
        String edescription=email.plainTextBody;
        String eindustry=email.subject;
		if(eindustry.contains('Account')){
        Account acc=new
        Account(name=ename,description=edescription,industry=eindustry);
        insert acc;
		}
		else{
			
	   Account 1=new
        Account(name=ename,description=edescription,industry=eindustry);
        
        insert a ; 
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.AccountId = a.Id;
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
		
		}
        return null;
    }
}