You need to sign in to do that
Don't have an account?
chikku
Error occurred while saving the apex class and trigger ,there is any resolved solution?
The above pic is an error, here is the code.
TimelineEventController:
TransactionAct code:
There is any resolved solution.for this?
TimelineEventController:
public class TimelineEventController implements IController, ITimelineEventController{ public static List<SObject> getAll(){ return [SELECT Name,Event_Date__c,Event_Type__c,Related_Id__c,Related_Object_Name__c, Related_User_Id__c,Title__c,Description__c,Object_Id__c FROM Timeline_Event__c ORDER BY CreatedDate DESC LIMIT 1000]; } @AuraEnabled public static List<SObject> getAll(SObject value){ return getAll(value,null); } public static List<SObject> getAll(SObject value,String autoNumber){ Timeline_Event__c param = (Timeline_Event__c)value; String queryString = 'Select Name,Event_Date__c,Event_Type__c,Related_Id__c,Object_Id__c,'+ 'Related_User_Id__c,Title__c,Subtitle__c,Description__c,Related_Object_Name__c'+ ' from Timeline_Event__c where'; if(!string.isBlank(autoNumber)){ queryString += ' Name = \'' + String.escapeSingleQuotes(autoNumber) + '\' AND'; } if(param.Event_Date__c != Null){ queryString += ' Event_Date__c = '+ param.Event_Date__c +' AND'; } if (!string.isBlank(param.Object_Id__c)) { queryString += ' Object_Id__c = \'' + String.escapeSingleQuotes(param.Object_Id__c) + '\' AND'; } if (!string.isBlank(param.Event_Type__c)) { queryString += ' Event_Type__c = \'' + String.escapeSingleQuotes(param.Event_Type__c) + '\' AND'; } if (!string.isBlank(param.Related_Id__c)) { queryString += ' Related_Id__c = \'' + String.escapeSingleQuotes(param.Related_Id__c) + '\' AND'; } if (!string.isBlank(param.Related_User_Id__c)) { queryString += ' Related_User_Id__c = \'' + String.escapeSingleQuotes(param.Related_User_Id__c) + '\' AND'; } if (!string.isBlank(param.Title__c)) { queryString += ' Title__c = \'' + String.escapeSingleQuotes(param.Title__c) + '\''; } queryString = queryString.removeEnd(' AND'); List<SObject> timeline=Database.query(queryString); return timeline; } @AuraEnabled public static SObject getById(Id id){ SObject entity = [SELECT Name,Event_Date__c,Event_Type__c,Related_Id__c,Object_Id__c, Related_User_Id__c,Title__c,Subtitle__c,Description__c, Related_Object_Name__c FROM Timeline_Event__c WHERE Id=:id]; return entity; } public Id create(SObject value) { Timeline_Event__c entity = (Timeline_Event__c)value; insert entity; return entity.Id; } public Boolean createMany(List<SObject> values) { List<Timeline_Event__c> entities = (List<Timeline_Event__c>)values; insert entities; return true; } public Boolean edit(SObject value) { Timeline_Event__c entity = (Timeline_Event__c)value; update entity; return true; } public Boolean editMany(List<SObject> values) { List<Timeline_Event__c> entities = (List<Timeline_Event__c>)values; update entities; return true; } public Boolean remove(Id id) { Timeline_Event__c entity = [SELECT Id FROM Timeline_Event__c WHERE Id=:id]; delete entity; return true; } @AuraEnabled public static List<SObject> getAllByLimit(Id id,Integer l){ List<sObject> entities=[SELECT Name,Event_Date__c,Event_Type__c,Related_Id__c,Object_Id__c, Related_User_Id__c,Title__c,Subtitle__c,Description__c, Related_Object_Name__c FROM Timeline_Event__c WHERE Object_Id__c = :id ORDER BY Id DESC LIMIT :l]; return entities; } public static SObject timelineTrigger(SObject obj,string tit,string sub,string des,string etype,string dml,string objName){ Timeline_Event__c tobj=new Timeline_Event__c(); SObject sObj; string objId=''; if(objName=='application'){ sObj=(Application__c)obj; tobj.Related_Object_Name__c='Application__c'; if(sObj.get('Account__c')!=null){ tobj.Object_Id__c=(string)sObj.get('Account__c'); } else{ tobj.Object_Id__c=(string)sObj.get('Contact__c'); } } else if(objName=='bank'){ sObj=(Bank_Account__c)obj; tobj.Related_Object_Name__c='Bank_Account__c'; if(sObj.get('Account__c')!=null){ tobj.Object_Id__c=(string)sObj.get('Account__c'); } else{ tobj.Object_Id__c=(string)sObj.get('Client__c'); } } else if(objName=='benefit'){ sObj=(Benefit__c)obj; tobj.Related_Object_Name__c='Benefit__c'; tobj.Object_Id__c=(string)sObj.get('Contact__c'); } else if(objName=='contact'){ sObj=(Contact)obj; tobj.Related_Object_Name__c='Contact'; tobj.Object_Id__c=(string)sObj.get('Id'); } else if(objName=='account'){ sObj=(Account)obj; tobj.Related_Object_Name__c='Account'; tobj.Object_Id__c=(string)sObj.get('Id'); } else if(objName=='employment'){ sObj=(Employment__c)obj; tobj.Related_Object_Name__c='Employment__c'; tobj.Object_Id__c=(string)sObj.get('Contact__c'); } else if(objName=='expense'){ sObj=(Expense__c)obj; tobj.Related_Object_Name__c='Expense__c'; tobj.Object_Id__c=(string)sObj.get('Contact__c'); } else if(objName=='loan'){ sObj=(Loan__c)obj; tobj.Related_Object_Name__c='Loan__c'; if(sObj.get('Account__c')!=null){ tobj.Object_Id__c=(string)sObj.get('Account__c'); } else{ tobj.Object_Id__c=(string)sObj.get('Contact__c'); } } else if(objName=='trans'){ IController Transloan=new LoanController(); Loan__c tloan=new Loan__c(); sObj=(Loan_Transaction__c)obj; tobj.Related_Object_Name__c='Loan_Transaction__c'; sObj=Transloan.getById('tloan'); if(tloan.Account__c!=null){ tobj.Object_Id__c=tloan.Account__c; } else{ tobj.Object_Id__c=tloan.Contact__c; } } if(objName=='employment'){ tobj.Event_Date__c=(DateTime)sObj.get('Start_Date__c'); } else if(dml=='insert'){ tobj.Event_Date__c=(DateTime)sObj.get('CreatedDate'); } else{ tobj.Event_Date__c=(DateTime)sObj.get('LastModifiedDate'); } tobj.Subtitle__c=sub; tobj.Event_Type__c=etype; tobj.Title__c=tit; tobj.Related_Id__c=(Id)sObj.get('Id'); tobj.Related_User_Id__c=(Id)sObj.get('LastModifiedById'); tobj.Description__c=des; return tobj; } public static string aLink(Id lid,String word){ return '<a href="/lightning/r/'+ lid +'/view">'+ word +'</a>'; } @AuraEnabled public static string getIdPrefix(){ Schema.DescribeSObjectResult k=Application__c.sObjectType.getDescribe(); return k.getKeyPrefix(); } @AuraEnabled public static string getUserName(Id id){ UserController userObj=new UserController(); User userDetails= (User)userObj.getById(id); return userDetails.Name; } }
TransactionAct code:
trigger TransactionAct on Loan_Transaction__c (after insert) { List<Timeline_Event__c> timelineList=new List<Timeline_Event__c>(); TimelineEventController tobj=new TimelineEventController(); ITimelineEventController timeAssignCtrl=new TimelineEventController(); for( Loan_Transaction__c trans :Trigger.New){ Timeline_Event__c tEvent=new Timeline_Event__c(); string rtype='', subtitle=''; if( Trigger.isInsert){ if(trans.Type__c=='Disbursal'){ subtitle=rtype+'Disbursal of'; tevent=(Timeline_Event__c)timeAssignCtrl.timelineTrigger(trans, '', subtitle,'', '','insert','trans'); timelineList.add(tEvent); } else if(trans.Type__c=='Payment'){ subtitle=rtype+'Payment of'; tevent=(Timeline_Event__c)timeAssignCtrl.timelineTrigger(trans,'', subtitle,'', '','insert','trans'); timelineList.add(tEvent); } } } tobj.createMany(timelineList); }
There is any resolved solution.for this?
What are you trying to achieve from the below line:
sObj=Transloan.getById('tloan');
You getById returns a record of Timeline_Event__c object and you are trying to store it in differen object type i.e. Loan__c. Since both of them are different thar's why you are getting the error.
If you have any lookup field of Timeline_Event__c object on Loan__c object than please use the below line :
tloan.Timeline_Event__c = Transloan.getById('tloan');
Let me know if this works for you or if you need any other help.
Thanks,
Abhishek Bansal.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Phone: +917357512102