+ Start a Discussion
ram_devram_dev 

Generate a Case based on Contact field and assigned to user

Hi,

 

Contacts that have oracleid's sfdc needs to generate case and assigned to perticuler user when contacts are updated.

can anyone help me out from this.

 

 

 

Thanks & Regards

Rama

Best Answer chosen by Admin (Salesforce Developers) 
@anilbathula@@anilbathula@

Hi ram_dev

with out passing any values to new case .
how a case will be created? and you are saying its working fine.
just go with code:-

Trigger updatecontact on Contact(after insert,after update)
{
case[] cases = new case[0];
user u=[select id from user where Name='Hecthick'];
For(Contact con:trigger.new){
If (con.phone != null)//make the condition perfect otherwise it creates multiple cases when ever you edit the contact and save it.
{

Case c = new Case();
c.Subject = 'Remedial Case';
c.Type = 'Remedial Work';
c.Status='Web';
c.ContactId=con.id;
c.origin='Phone';
c.ownerid=u.id;
cases.add(c);

}
}
Insert cases;
}

All Answers

ram_devram_dev

Hi,

 i wrote the below trigger but it showss the error like invalid field whoid for sobject case.below is the code; can any one help me from this.

 

Trigger updatecontact on Contact(after insert,after update)

{

case[] cases = new case[0];

For(Contact con:trigger.new){

If (con.phone != null)

{

cases.add(new case(whoid=con.id));

}

}

Insert cases;

}

 

 

 

 

@anilbathula@@anilbathula@
Hi ram_dev

Instead of whoid pass Contactid=con.id
ram_devram_dev

Hi anil,

 

Thankyou. here am update the code which works fine. but i need some more information to assigned case to perticuler user. Any one please helpme out from this problem.

 

Trigger updatecontact on Contact(after insert,after update)

{

case[] cases = new case[0];

For(Contact con:trigger.new){

If (con.phone != null)

{

cases.add(new case());

}

}

Insert cases;

}

 

 

@anilbathula@@anilbathula@

Hi ram_dev

with out passing any values to new case .
how a case will be created? and you are saying its working fine.
just go with code:-

Trigger updatecontact on Contact(after insert,after update)
{
case[] cases = new case[0];
user u=[select id from user where Name='Hecthick'];
For(Contact con:trigger.new){
If (con.phone != null)//make the condition perfect otherwise it creates multiple cases when ever you edit the contact and save it.
{

Case c = new Case();
c.Subject = 'Remedial Case';
c.Type = 'Remedial Work';
c.Status='Web';
c.ContactId=con.id;
c.origin='Phone';
c.ownerid=u.id;
cases.add(c);

}
}
Insert cases;
}

This was selected as the best answer
ram_devram_dev

HI anil,

 

It is working. Thank you for your time. and sorry for the late reply hence was out of offiice these days.

 

 

Thankyou

Ram