Class Apex-Salesforce.com-我需要帮助编写一个Apex类来测试我的工作触发器-聊天器-监视器特定关键字

Class Apex-Salesforce.com-我需要帮助编写一个Apex类来测试我的工作触发器-聊天器-监视器特定关键字,class,triggers,salesforce,salesforce-chatter,Class,Triggers,Salesforce,Salesforce Chatter,这是我的工作触发器 trigger CheckChatterPostsOnNSP on FeedItem (before insert) { Set<Id> nspIds = new Set<Id>(); //Get the NSP that will be updated List<Non_Standard_Pricing__c> nsp2Update = new List<Non_Standard_Pricing__c>(); //Get

这是我的工作触发器

trigger CheckChatterPostsOnNSP on FeedItem (before insert) {

Set<Id> nspIds = new Set<Id>();

//Get the NSP that will be updated
List<Non_Standard_Pricing__c> nsp2Update = new List<Non_Standard_Pricing__c>();

//Get the key prefix for the NSP object via a describe call.
String nspKeyPrefix = Non_Standard_Pricing__c.sObjectType.getDescribe().getKeyPrefix();

//Get the Id of the user
Id profileId = UserInfo.getProfileId();

for (FeedItem f: trigger.new) {
    String parentId = f.parentId;

    if(profileId == '00e30000000eWXR') {// Users profile must be Sales and Service
        //We compare the start of the 'parentID' field to the NSP key prefix to
        //restrict the trigger to act on posts made to the NSP object.
        if (
            parentId.startsWith(nspKeyPrefix) &&
            (
                f.Body.contains('***APPROVED BY CHANNEL***') || 
                f.Body.contains('***APPROVED BY CSM***') || 
                f.Body.contains('[APPROVED BY CHANNEL]') || 
                f.Body.contains('[APPROVED BY CSM]')
            )
        ){
            nspIds.add(f.parentId);
        }
    }
}
List < Non_Standard_Pricing__c > nsps = [select id, Pre_Approved_Service_Discount__c, ownerId
from Non_Standard_Pricing__c where id in :nspIds];

for (Non_Standard_Pricing__c n: nsps) {
    //We compare the creator of the Chatter post to the NSP Owner to ensure
    //that only authorized users can close the NSP using the special Chatter 'hot-key'

        n.Pre_Approved_Service_Discount__c = true;
        nsp2Update.add(n);
    }
    update nsp2Update;
}
我得到以下错误 消息:System.QueryException:列表中没有可分配给SObject的行 堆栈跟踪:Class.checkChatterPostSonSpTest.checkChatterPostSonSpTest:第14行第1列


非常感谢您的帮助。

这将指向这一行:

Profile SalesNService = [Select id from Profile where Name = 'Sales and Service' limit 1];
只需检查此查询是否返回某些内容?个人资料名称输入错误(可能有下划线或“销售与服务”)?也许在组织中根本就没有这样的配置文件(例如,如果您在生产环境中创建了这样的配置文件,但您所在的沙箱之后没有刷新)

恐怕我们帮不了你更多;)它甚至不能与API版本、“seeAllData”等相关,因为

Profile SalesNService = [Select id from Profile where Name = 'Sales and Service' limit 1];