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
KatherineCKatherineC 

How to create a Pint automatically when a Case is created?

Hi All,
I created an Object Pint, we want the Pint to be self-generated when a Case is created and the case type is Rate Change, I get error message that invalid type.

trigger AutoCreatePin on Case (after insert) {
       for (Case c : Trigger.new) {
               if (c.Type == 'Rate Change') {
                       Pint p = new Pint();
            p.AccountId = c.AccountId;
                    insert p;
        }
    }
}


Error: Compile Error: Invalid type: Pint at line 4 column 32

Even I change to "Pint_c" it still says invalid type. Anyone can tell me why?

Thanks.
Best Answer chosen by KatherineC
Shingo YamazakiShingo Yamazaki
You should use "AccountId" field of SObject Case.
p.Account__c = c.AccountId;

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_case.htm

All Answers

Shingo YamazakiShingo Yamazaki
Dear kat,

Hello.
I'm Shingo Yamazaki.

Did you change BOTH "Pint" like this?

// -----------before--------------
Pint p = new Pint();

// -----------after-----------------
Pint__c p = new Pint__c();



KatherineCKatherineC
Hi Shingo,

Yes, I changed both Pint to Pint_c it still says invalid type, don't know why.
Shingo YamazakiShingo Yamazaki
Did you type 2 underscores?

Not "Pint_c" but "Pint__c".

If so, have you already created or deployed the custom object "Pint__c"?
KatherineCKatherineC
Oh I just realized it's 2 underscores!! Thanks, Shingo, now this line is fine. Then I got another error about Account :(

trigger AutoCreatePin on Case (after insert) {
       for (Case c : Trigger.new) {
               if (c.Type == 'Rate Change') {
                       Pint__c p = new Pint__c();
                       p.Account__c = c.Account;
               insert p;
        }
    }
}

Error: Compile Error: Illegal assignment from SOBJECT:Account to Id at line 5 column 24

I just want to make sure it's under the same account so I put "p.Account__c = c.Account;" is it wrong again?
Shingo YamazakiShingo Yamazaki
You should use "AccountId" field of SObject Case.
p.Account__c = c.AccountId;

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_case.htm
This was selected as the best answer
KatherineCKatherineC
Yes, it works now, thanks a lot!!!