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
bhanu_prakashbhanu_prakash 

Create case using chatbot

Hi Team,

Iam creating chatbot to create a case . I have created slot name as

description   datatype as Text
Priority         datatype as Text
and iam trying to create a case using inovcable case , unable to create case
case contact need to logined in user contact name and account name need to be logined user account name.
 
public class ChatBotCreateCase {    
    @InvocableMethod(label='Create a Case' description='New case creation for the specified text')   
    public static List<Case> CreateCases(List<CreateCaseString> requests){               
        List<Case> results = new List<Case>(); 
        for(CreateCaseString request: requests){
            system.debug('Case Results:' +request.value);
            if(request.ObjCase !=null && request.ObjCase.Id != null && String.isNotBlank(request.value)){
                User us = [select id, Name,User.Contact.AccountId,User.Contact.Name from User where id =: UserInfo.getUserId()];
                Case newCase = request.ObjCase;
                newCase.Status = 'New';          
                newCase.Origin = 'Web';
                newCase.Subject = 'Reach out to user ' + us.Contact.Name + ' having email id ' + us.Contact.Email + ' for following question ';                 
                insert newCase;
                list<User> communityUser = [select id, Name,User.Contact.AccountId,User.Contact.Name from User WHERE id =: UserInfo.getUserId()];{
                    User Currentuser = Communityuser[0];
                    Currentuser.Phone = request.value;
                    update Currentuser;
                }
                return new List<Case>{newCase};            
                    }
        }
        return new list<Case>{requests[0].Objcase};     
            }     
    
    public class CreateCaseString{
        @InvocableVariable
        public string value;
        @InvocableVariable
        public Case ObjCase;
    }
    
}

Thanks for advance