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
Kevin LanguedocKevin Languedoc 

Apex class : invalid type

I wrote a class to send email from Force.com ide. When I try to reference it in a trigger I get an invalid type error. Do I have to create a package or use an import statement?

 

this is the trigger....

 

trigger SendAccountMasterUpdates on Account (after insert, after update) {

 

if(Trigger.isInsert)

{

for(Account a : Trigger.new)

{

if(a.Transaction_Account__c == true)

{

SendAccountUpdateMessage mail = new SendAccountUpdateMessage();

}

}

 

}else

{

 

 

}

 

}

 

this is the apex class....

 

 

public with sharing class SendAccountUpdateMessage {

 

public void SendAccountInformation()

{

     .....

}

 

}

Best Answer chosen by Admin (Salesforce Developers) 
Kevin LanguedocKevin Languedoc

Hi John,

 

I did the same thing, please see my previous post.

 

The last time I worked on a Salesforce project was in the Winter '09 (API 14.0). Back then I was able to create the classes in the IDE and deploy directly to production environment. I guess Salesforce changes things a bit since then. What I did today was create the class and trigger in the dev org and then export them to my IDE and everything works OK.

 

I will use the Apex Deployment Tool to deploy the class and trigger to the prod org.

 

Anyway, thanks for your support I really appreciate it.

All Answers

jhenningjhenning
No need for a package or import. Your code should work so there must be some other problem. Can you post the whole class and trigger? What line number is throwing the error?
Kevin LanguedocKevin Languedoc

Hi

 

Here is the SendAccountUpdateMessage class. The mailer is a copy of the example from the Salesforce site. I am using the new Flash Builder 4 for Salesforce IDE.

 

public with sharing class SendAccountUpdateMessage {

 

public void SendAccountInformation()

{

 

 

// Create a new single email message object

// that will send out a single email to the addresses in the To, CC & BCC list.

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

// Strings to hold the email addresses to which you are sending the email.

String[] toAddresses = new String[] {'SFCustomerMaster@draxis.com'}; String[] ccAddresses = new String[] {'klanguedoc@draxis.com'};

 

 

// Assign the addresses for the To and CC lists to the mail object.

mail.setToAddresses(toAddresses);

mail.setCcAddresses(ccAddresses);

 

 

 

 

// Specify the name used as the display name.

mail.setSenderDisplayName('Salesforce Account Master Sync');

 

// Specify the subject line for your email address.

mail.setSubject('Account : 000000');

 

// Set to True if you want to BCC yourself on the email.

mail.setBccSender(false);

 

// Optionally append the salesforce.com email signature to the email.

// The email address of the user executing the Apex Code will be used.

mail.setUseSignature(false);

 

// Specify the text content of the email.

mail.setPlainTextBody('Test ');

 

//mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+

// ' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');

 

// Send the email you have created.

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

}

 

}

 

Here is the complete code for the trigger, the error is on line 9

 

trigger SendAccountMasterUpdates on Account (after insert, after update) {

 

if(Trigger.isInsert)

{

for(Account a : Trigger.new)

{

if(a.Transaction_Account__c == true)

{

SendAccountUpdateMessage mail = new SendAccountUpdateMessage();

mail.SendAccountInformation();

}

}

 

}else

{

 

 

}

 

}

 

 

Kevin LanguedocKevin Languedoc

Hi jhenning,

 

Just a thought...When I created the class with the new Flash Builder4, the API version listed in the combobox was 16, is this the correct version, or should it be at 18?

Kevin LanguedocKevin Languedoc

I tried changing the ApiVersion to 18.0 in the metadata, but this didn't do anything. Afterwhich I had the idea to try and create the trigger and Apex Class directly in Salesforce Developer Edition. Surprisingly it works fine. The trigger and Apex Class "SendAccountUpdateMessage" work perfectly and with no compile errors. This is ok for the dev environment, but I can't create Apex code or triggers this way in the Production Environment, so why can't I do the same in the Force IDE?

jhenningjhenning

kevDI,

 

I took your code and created the class and trigger successfully in a dev org I have and it compiled fine. I'm not sure I understand exactly what environment in which you are trying to create this Apex code. I used the Force.com IDE (eclipse).  You can never create Apex directly in production, it has to be deployed via the IDE, Ant or some other deployment tool.

Kevin LanguedocKevin Languedoc

Hi John,

 

I did the same thing, please see my previous post.

 

The last time I worked on a Salesforce project was in the Winter '09 (API 14.0). Back then I was able to create the classes in the IDE and deploy directly to production environment. I guess Salesforce changes things a bit since then. What I did today was create the class and trigger in the dev org and then export them to my IDE and everything works OK.

 

I will use the Apex Deployment Tool to deploy the class and trigger to the prod org.

 

Anyway, thanks for your support I really appreciate it.

This was selected as the best answer