+ Start a Discussion
Kim BryantKim Bryant 

Apex Class error 'variable does not exist' when trying to reference a custom object

Trying to write a apex class for making Salesforce and PayPal work via Form Assembly. I've created a custom object called Donation and am using a template coding provided by From Assembly support (http://www3.formassembly.com/blog/doc/connectors/salesforce/advanced-integration/making-salesforce-and-paypal-work-together/). I changed the code to replace where it referenced Opportunity to reference my custom object Donation__c. But I get the error ' Error: Compile Error: Variable does not exist: donation__c at line 8 column 9'. Below is the cod I'm using. Any Ideas?

public class IPNHandlerController {

    public PageReference myIPNupdate() {
     try{
        PageReference pageRef = ApexPages.currentPage();
        //Get the value of the 'custom' parameter from current page
        String paramCustom = pageRef.getParameters().get('custom');
        donation__c = [select Id,paid__c from Donation__c where FormAssemblyID__c = :paramCustom ];

        String content = '';
        for(String key : pageRef.getParameters().keySet()){
            //Note that there is no guarantee of order in the parameter key map.
            content += key + ' : ' + pageRef.getParameters().get(key) + '\n';
        }
        Donation__c.PayPalInfo__c = content;
        Donation__c.paid__c = True;
        update Donation__c;

        PageReference newPage = new ApexPages.StandardController(Donation__c).view();
        newPage.setRedirect(true);       

        return newPage;
     } catch (System.Exception e){
         //A failure occurred
         system.debug(e);
         return null;
     }
    }

    public Opportunity opportunity {get; set;}

    public IPNHandlerController() {
    }
}
Best Answer chosen by Kim Bryant
Eric_SalesForceEric_SalesForce
Lets say you replaced Donation__c at line 8 to Donation__c donationObj.... now you reference that object by donationObj NOT donation__c so on your upsert say upsert donationOBj; 

All Answers

Eric_SalesForceEric_SalesForce

donation__c is the SObject TYPE you need to name it. For example donation__c donatationObj = [Select ....
would do the trick.

Kim BryantKim Bryant
I've tried your suggestion. Now I get the error 'Error: Compile Error: Variable does not exist: Donation__c at line 17 column 16'
Eric_SalesForceEric_SalesForce
Lets say you replaced Donation__c at line 8 to Donation__c donationObj.... now you reference that object by donationObj NOT donation__c so on your upsert say upsert donationOBj; 

This was selected as the best answer
Kim BryantKim Bryant
Thanks. That resolved the variable does not exist. Now it just tells me 'Error: Compile Error: Expression cannot be assigned at line -1 column -1'. Which doesn't make sense to me as there is no -1 lin column -1
Eric_SalesForceEric_SalesForce
Without being able to go into this myself and add system.debug logs to check for where the error occurs it is hard for me to say. One thing I noticed is that the catch from your try/catch has code above it that is not in the try. That might be where the compiler is getting confused. Outside of that I am really not sure, I would recomment stepping through with system debug logs and using the developer console to locate the errors you are facing. Hope that helped.