+ Start a Discussion
RajevlsRajevls 

Record not getting inserted into the custom object

I am using an after insert trigger on Task to insert a record into the custom object when Status = Completed

 

 if(trigger.isinsert)
    {
        List<OAR_Member_Added__c> objList = new List<OAR_Member_Added__c>();
        OAR_Member_Added__c obj = new OAR_Member_Added__c();
        for(Task T: Trigger.new){ 
            if(((T.RecordTypeId == '01270000000Q9KJ')||(T.RecordTypeId == '012S0000000DIPs')||(T.RecordTypeId == '012V0000000Co5k'))&&(T.Status == 'Completed')){


                obj.Text_1__c = T.Type__c;
                obj.Text_2__c = T.Type_Detail__c;
                obj.Text_3__c = T.Subject;
                obj.Text_4__c = T.Description;
                if((String.valueof(T.Owner)).substring(0,2)== '005'){
                obj.User_1__c = String.valueof(T.Owner);
                 }
                 String urlForObj= URL.getSalesforceBaseUrl().toExternalForm() + '/'+T.WhatId;
                obj.Task_Url__c = urlForObj; 
                objList.add(obj);
            }
        }
        insert objList;
    }

 

Please help .

kiranmutturukiranmutturu

try like this

 

if(trigger.isinsert)
{
List<OAR_Member_Added__c> objList = new List<OAR_Member_Added__c>();

set<RecordType> rtypes = [Select Id From RecordType where sObjectType='Task' and isActive=true];

for(Task T: Trigger.new){
if((rtypes.contains(T.RecordTypeId))&&(T.Status == 'Completed')){
OAR_Member_Added__c obj = new OAR_Member_Added__c();
obj.Text_1__c = T.Type__c;
obj.Text_2__c = T.Type_Detail__c;
obj.Text_3__c = T.Subject;
obj.Text_4__c = T.Description;
if((String.valueof(T.Ownerid)).substring(0,2)== '005'){
obj.User_1__c = String.valueof(T.Owner);
}
String urlForObj= URL.getSalesforceBaseUrl().toExternalForm() + '/'+T.WhatId;
obj.Task_Url__c = urlForObj;
objList.add(obj);
}
}
if(!objList.isEmpty())
insert objList;
}

RajevlsRajevls

Error is coming up for the line  :

 

set<RecordType> rtypes = [Select Id From RecordType where sObjectType='Task' and isActive=true and Name = 'Renewals_Record_Type'];

 

Error : 
Error: Compile Error: Illegal assignment from LIST<RecordType> to SET<RecordType> at line 67 column 1

kiranmutturukiranmutturu

then change like this

 

list<RecordType> rtypes = [Select Id From RecordType where sObjectType='Account'];
set<recordtype> stypes = new set<recordtype>();
boolean b = stypes.addAll(rtypes);

RajevlsRajevls

list<RecordType> rtypes = [Select Id From RecordType where sObjectType='Task' and name = 'Renewals_Record_Type'];
set<recordtype> stypes = new set<recordtype>();
boolean b = stypes.addAll(rtypes);
for(Task T: Trigger.new){
if((b.contains(T.RecordTypeId))&&(T.Status == 'Completed')){

 

getting error on the line :if((b.contains(T.RecordTypeId))&&(T.Status == 'Completed')){ 

 

Error : Error: Compile Error: Method does not exist or incorrect signature: [Boolean].contains(Id) at line 71 column 5

kiranmutturukiranmutturu

replace b with stypes in if((b.contains(T.RecordTypeId))&&(T.Status == 'Completed')){ line

RajevlsRajevls

Error: Compile Error: Incompatible element type Id for collection of SOBJECT:RecordType at line 71 column 5

 

for the line :

 

if((stypes.contains(T.RecordTypeId))&&(T.Status == 'Completed')){

kiranmutturukiranmutturu

hahhaaa

just changed the query like this 

 

set<id> stypes = new set<i>();

for(recprdtype objr : [Select Id From RecordType where sObjectType='Task' and name = 'Renewals_Record_Type']){
     stypes.add(objr.id);

}

RajevlsRajevls

Now there are no errors on the code but the record is not getting inserted into the custom object

kiranmutturukiranmutturu

check it out is there any exception is coming in the debug?