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
muni u 5muni u 5 

How to create a SKILL through coding?

Hi All,
I have faced an issue while creating a SKILL coding.Can any help me that how to create a SKILL through coding?

Below is the issue I have faced.
Skill Insert Error Cany some one help me ASAP.

Regards,
Muni.
muni u 5muni u 5
HI all,
Below is the code wchich I have tried to insert in the Anonymous window/Developer console.

Skill objSkill=new Skill();
objSkill.DeveloperName='A1';
objSkill.MasterLabel='A1';
insert objSkill;

below is the Error : 

Skill Insert
NagendraNagendra (Salesforce Developers) 
Hi Muni,

Sorry for this issue you are facing.

May I suggest you please double check if the user has create permission on skill object? If the user doesn't have the create permission on the skill object please give a try by giving the respective permission which might resolve the issue.

Still, if the problem persists let us know.

Happy to help further.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
Andrew GAndrew G
Hi

You cannot "Insert" Skill records with Apex.

I believe it is to do with how Skills were created under Salesforce - under Classic they were created via the Setup menu, not via the usual list view / new record type button.  Under lightning, something similar in that you have the FSL managed package and then it happens under that package.  

Regards

Andrew

 
muni u 5muni u 5
Hi Nagendra,
Firstly thanks for the response.I have created a permission set.In permisssion set under objects ,there is no "SKILL "object .I have no Idea how to give edit,create permission on that object.can u please check and tell me.
Regards,
Muni
muni u 5muni u 5
Hi Andrew,
Thanks for the response. I agree with u.In my apex class I have created a serviceResourceSkill with SKILLId.In test class I need to do code coverage for that apex.But In the test class I am unable to Insert a Skill.Then how can I do my code coverage.Any Idea?

Regards,
Muni
Andrew GAndrew G
Hi Muni

Sorry for the delay, but in new job now.

I created 2 x skills in the my org and ensured their name contained "TEST".  I then created the test class so I could then query them by name for the details such as Id and AutoGenerate

We also had "filters" on the Skill lookup fields which limited which Skills the end user would see so that they would not mistakenly use the TEST skills.

Regards
Andrew
muni u 5muni u 5
Hi Andrew,
Can you please share the code if possible.
I don't think that we will write Queries in Test classes.And again we shouldn't give Static Id's that cause test class fail during deployment.
If possible please forward the code.

Regards,
Muni
Andrew GAndrew G
//Skills can't be inserted so pull from live Skills - ensure Test skills exists
        Skill maintSkill = [SELECT Id, MasterLabel FROM Skill WHERE MasterLabel LIKE 'Maintenance - Test' Limit 1];

        SkillRequirement maintSR = new SkillRequirement (RelatedRecordId = newWt.id, SkillId = maintSkill.Id);
        insert maintSR;

Here is a sample of the query I used.  In this case, I was using it for a Skill Requirement record.

Regards

Andrew