-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
7Questions
-
12Replies
Please help bulkify this trigger
My incredibly rudimentary SFDC coding skills came up with the trigger below but it's resulting in "too many SOQL queries" errors. I'd appreciate some help bulkifying it.
Thanks.
Thanks.
trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) { Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>(); Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>(); Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0]; for(Insurance_Case__c record: Trigger.new){ Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id); if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){ casesstatus.put(record.Id, record); } else { cases.put(record.Id, record); } } Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract']; Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract']; for(Agent_Cases_Commissions__c acc :accstatus){ acc.Case_Status_Change__c = TRUE; accToUpdate.add(acc); } for(Agent_Cases_Commissions__c acc2 :accnostatus){ accToUpdate.add(acc2); } if(!accToUpdate.isEmpty()) update accToUpdate; }
- Lloyd Silver
- September 19, 2014
- Like
- 0
SFDC as identity provider - login cookie
I'm using SFDC as an identity provider for a SAML logon to a WordPress site. As of now, each time a user closes his browser they have to log back in. Is there any way of setting a cookie so that they remain in a logged in status for a longer period of time?
- Lloyd Silver
- July 03, 2014
- Like
- 1
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '"
I had someone edit a class and unfortunately they've gone missing and I'm getting an error when deploying:
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
public without sharing class EstimateCommList { public list<Data_Estimated_Comm> LDEC {get;set;} public User user; public String curruserid; public String CId; public String sort_by {get;set;} public Date from_date {get;set;} public Date to_date {get;set;} public string fromdate{get; set;} public string todate{get; set;} public map<string,List<string>> JuniorContactsMap; public String User_Selection{get;set;} public Boolean IsEmptyList{get;set;} public List<string> cLst; public Boolean hasAgencyAccess{get;set;} public Boolean IsAgency{get;set;} public map<string,string> AccountMap; public Date StartingDate; public EstimateCommList() { curruserid = UserInfo.getUserId(); system.debug('curruserid:'+curruserid); //get user record with contact__c user = [Select u.Name, u.Id, u.ContactId,u.contact.accountid,u.contact.Agency_Commission_Access__c From User u where u.Id =:curruserid]; CId = user.ContactId; if(user.contact.Agency_Commission_Access__c==true){ hasAgencyAccess=true; } else{ hasAgencyAccess=false; } IsAgency=false; if(test.isrunningtest()){ User_Selection=CId; } system.debug('CId:'+CId); //Added for Datepicker variale convertion into date time. fromdate=string.valueOf(string.valueOf(System.today().month()+'/'+System.today().day()+'/'+System.today().year())); system.debug('@@@@@@@@@@'+fromdate); todate= string.valueOf(System.today().addmonths(6).month()+'/'+System.today().addmonths(6).day()+'/'+System.today().addmonths(6).year()); system.debug('@@@@@@@@@@'+todate); IsEmptyList=false; system.debug('**************'+IsEmptyList); JuniorContactsMap=new map<string,List<string>>(); for(contact g:[select id,name,ReportsToId from contact]){ if(JuniorContactsMap.containskey(g.ReportsToId)){ JuniorContactsMap.get(g.ReportsToId).add(g.id); } else{ list<string> temp=new List<string>(); temp.add(g.id); JuniorContactsMap.put(g.ReportsToId,temp); } } system.debug('################'+JuniorContactsMap); cLst=new List<string>(); cLst.add(CId); List<string> cLst1=new List<string>(); cLst1.add(CId); List<string> TList=new List<string>(); TList.add('Test'); while(TList.size() >=1){ system.debug('^^^^^^^^^^^^^^^^^'+cLst1); List<string> TempConList=Childcontacts(cLst1); if(TempConList.size()>0){ cLst.addall(TempConList); cLst1=TempConList; } else{ TList.remove(0); } } system.debug('***************'+cLst); StartingDate=date.newinstance(2014,7,1); system.debug('######'+StartingDate); list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, e.Insurance_Case__r.name, e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name, e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,e.Insurance_Case__r.Submitted_Date__c, e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name From Estimated_Commissions__c e where e.Agent__c =:CId AND e.Insurance_Case__r.Submitted_Date__c >=: StartingDate order by CreatedDate desc limit 1000 ]; system.debug('LEC:'+LEC); if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c EC : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = EC.Agency__r.Name; DEC.Agent = EC.Agent__r.Name; DEC.Casesplit = EC.Case_Split__c; DEC.ExcessCommAmt = EC.Excess_Commission_amount__c; DEC.ExcessCommRate = EC.Excess_Commission_Rate__c; DEC.FYCAmt = EC.FYC_Amount__c; DEC.FYCRate = EC.FYC_Rate__c; DEC.Insurance_Commission_Name = EC.Name; DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name; DEC.Product = EC.Insurance_Case__r.Product__r.Name; DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c; DEC.Premium = EC.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = EC.Valid_From__c; //new changes DEC.InsuranceCase= EC.Insurance_Case__c; DEC.InsuranceCaseName= EC.Insurance_Case__r.Name; LDEC.add(DEC); } } public List<SelectOption> getSort() { List<SelectOption> options1 = new List<SelectOption>(); options1.add(new SelectOption('Valid_From__c','Date')); options1.add(new SelectOption('Agent__r.Name','Agent Name')); options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier')); options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business')); options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product')); options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number')); options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client')); options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode')); options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium')); options1.add(new SelectOption('FYC_Rate__c','FYC Rate')); options1.add(new SelectOption('FYC_Amount__c','FYC Amount')); options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate')); options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount')); return options1; } //Method which will call each time for inner hierarchy of contacts public List<string> Childcontacts(List<string> CurrentContactsIDList){ List<string> d=new List<string>(); for(string w:CurrentContactsIDList){ system.debug('%%%%%%%%%%%%%%%'+w+'-'+JuniorContactsMap.get(w)); if(JuniorContactsMap.containskey(w)){ for(string l:JuniorContactsMap.get(w)){ d.add(l); } } } return d; } //Method which will have all users list in hierarchy of user logged in public List<SelectOption> getAllusers() { List<SelectOption> options1 = new List<SelectOption>(); AccountMap=new MAp<string,string>(); integer i=0; List<contact> mylst=[select id,name,accountid from contact where id IN:cLst]; for(contact w:[select id,name,accountid from contact where id IN:cLst]){ AccountMap.put(w.id,w.accountid); if(w.id==CId){ contact q=mylst[0]; mylst[0]=mylst[i]; mylst[i]=q; } i++; } system.debug('###############'+AccountMap); for(contact c:mylst){ options1.add(new SelectOption(c.id,c.name)); } return options1; } public pagereference searchEsti() { List<Estimated_Commissions__c> LEC = new List<Estimated_Commissions__c>{}; //New chanages as part of input date picker format changes Datetime Dt1; string Dt2; Datetime Dt3; string Dt4; system.debug('##############'+fromdate+'-'+todate); if(fromdate !=null && fromdate !=''){ List<string> a=fromdate.split('/'); Dt1=Datetime.newinstance(integer.valueOf(a[2]),integer.valueOf(a[0]),integer.valueOf(a[1])); Dt2=Dt1.format('yyyy-MM-dd'); } else{ Dt2=null; } if(todate !=null && todate !=''){ List<string> b=todate.split('/'); Dt3=Datetime.newinstance(integer.valueOf(b[2]),integer.valueOf(b[0]),integer.valueOf(b[1])); Dt4=Dt3.format('yyyy-MM-dd'); } else{ Dt4=null; } system.debug('######'+Dt2+'-'+Dt4); String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,e.Insurance_Case__r.name,'; DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,'; DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; DB1 += 'e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Submitted_Date__c, '; DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name'; DB1 += ' From Estimated_Commissions__c e '; if(IsAgency==false){ DB1 += ' where e.Agent__c =\''+User_Selection+'\''; } else if(IsAgency==true){ //DB1 += ' where e.Agency__c =\''+AccountMap.get(User_Selection)+'\''; DB1 += ' where e.Agency__c =\''+user.Contact.accountId+'\''; } //New changes as part of input date chaanges DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= '+ StartingDate; if(Dt2!=null){ DB1 += ' and e.Valid_From__c >= ' + Dt2; } if(Dt4!=null){ DB1 += ' and e.Valid_From__c <= ' + Dt4; } DB1 += ' order by '+ sort_by + ' asc ' ; DB1 += ' limit 10'; system.debug('#################'+DB1); LEC = DataBase.query(DB1); system.debug('LEC:'+LEC); LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c est : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = est.Agency__r.Name; DEC.Agent = est.Agent__r.Name; DEC.Casesplit = est.Case_Split__c; DEC.ExcessCommAmt = est.Excess_Commission_amount__c; DEC.ExcessCommRate = est.Excess_Commission_Rate__c; DEC.FYCAmt = est.FYC_Amount__c; DEC.FYCRate = est.FYC_Rate__c; DEC.Insurance_Commission_Name = est.Name; DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name; DEC.Product = est.Insurance_Case__r.Product__r.Name; DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c; DEC.Premium = est.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = est.Valid_From__c; //new changes DEC.InsuranceCase= est.Insurance_Case__c; DEC.InsuranceCaseName= est.Insurance_Case__r.Name; LDEC.add(DEC); } return null; } }
/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest(SeeAllData=false) private class TestEstimateCommListClass { static testMethod void DoListTest() { RecordType r = [Select Name, Id From RecordType where Name ='Carriers' ]; profile w = [Select Name, Id From profile where Name ='Authenticated Website' ]; Account a= new Account(); a.Name = 'atest'; a.Type = r.Name; a.RecordTypeId = r.Id; system.debug('a:'+a); insert a; contact con=new contact(lastname='test two',accountid=a.id,Email='client321@mixcimizer.com'); insert con; User u = new User(); u.Username = 'cooks@gmail.com'; u.LastName = 'mycook'; u.Email = 'client321@mixcimizer.com'; u.profileid = w.id; u.contactid = con.id; u.alias =u.LastName.substring(0,4); u.CommunityNickname ='4321new'; u.MobilePhone ='9875643456'; u.TimeZoneSidKey = 'Asia/Kolkata'; u.LocaleSidKey = 'en_IE_EURO'; u.EmailEncodingKey = 'ISO-8859-1'; u.LanguageLocaleKey = 'en_US'; u.IsActive = true; INSERT U; Carrier_Product__c p = new Carrier_Product__c(); p.Name = 'ptest'; p.Carrier__c = a.Id; p.Line_of_Business__c = 'Life Insurance'; p.Plan_Type__c = 'Term Life Insurance'; insert p; Insurance_Case__c ic = new Insurance_Case__c(); ic.Carrier__c = a.Id; ic.Product__c = p.Id; ic.X1035_Exchange_Amount__c = 1000; ic.X1035_Exchange_Carrier__c = 'test'; ic.Approved_Rating_Additional_Insured__c = 'test'; ic.Approved_Rating_Primary_Insured__c = 'test'; ic.Elimination_Period__c = ''; ic.Excess_Premium__c = 1000; ic.Face_Amount__c = 500; ic.Line_of_Business__c = 'Life Insurance'; ic.Lump_Sum_Amount__c = 500; ic.Modal_Premium__c = 1000; ic.Policy_Number__c = '123'; ic.Premium_Mode__c = 'Monthly'; ic.Premium_Payment_Method__c = ''; ic.Policy_Date__c = system.today(); ic.Proposed_Face_Amount__c = 100; ic.Proposed_Premium__c = 100; ic.Proposed_Type_Of_Insurance__c = ''; ic.Rating_Applied_For_Additional_Insured__c = ''; ic.Rating_Applied_For_Primary_Insured__c = ''; ic.Source_of_Funds__c = ''; ic.State_of_Issue__c = 'Alabama'; ic.Status__c = 'Inforce'; ic.Target_Premium__c = 1000; insert ic; ic.X1035_Exchange_Amount__c = 2000; ic.X1035_Received_Date__c = system.today(); ic.X1035_Received__c = true; ic.Lump_Sum_Amount__c = 400; ic.Lump_Sum_Received__c = true; ic.Lump_Sum_Received_Date__c = system.today(); update ic; Estimated_Commissions__c e = new Estimated_Commissions__c(); e.Insurance_Case__c = ic.id; e.agent__c=con.id; insert e; system.runas(u){ EstimateCommList ecl = new EstimateCommList(); ecl.getAllusers(); ecl.getSort(); ecl.sort_by='Valid_From__c'; ecl.searchEsti(); Data_Estimated_Comm Dec = new Data_Estimated_Comm(); EstimateCommList ec2 = new EstimateCommList(); ec2.getAllusers(); ec2.getSort(); ec2.sort_by='Valid_From__c'; ec2.searchEsti(); } } }
- Lloyd Silver
- June 30, 2014
- Like
- 0
Force.com Site Login Redirect To External URL
I have a force.com site using authenticated website licenses along with SFDC setup as an identity provider for authentication on a WordPress site.
Users initiate login on the WordPress site at which point they are forwarded to a visualforce page where they can login, and then are redirected back to the WordPress site where they can access protected pages on the WordPress site as well as the force.com site pages.
Login via a visualforce page and then back to the WordPress site is required because of limitations with the authenticated website user license.
Everything works perfectly with one exception.
If the user has forgotten their password, they can click the forgot password link on the visualforce page. They complete the password reset process and are logged into the force.com site.
However, the single signon functionality was interrupted in the process.
So if they try to access the WordPress site's protected pages, they are asked to login again.
The only way I can get around this, as far as I can tell, is to redirect the user to an external URL (on the WordPress site) after they have logged in successfully following the password reset.
How can I do this?
Thanks
Users initiate login on the WordPress site at which point they are forwarded to a visualforce page where they can login, and then are redirected back to the WordPress site where they can access protected pages on the WordPress site as well as the force.com site pages.
Login via a visualforce page and then back to the WordPress site is required because of limitations with the authenticated website user license.
Everything works perfectly with one exception.
If the user has forgotten their password, they can click the forgot password link on the visualforce page. They complete the password reset process and are logged into the force.com site.
However, the single signon functionality was interrupted in the process.
So if they try to access the WordPress site's protected pages, they are asked to login again.
The only way I can get around this, as far as I can tell, is to redirect the user to an external URL (on the WordPress site) after they have logged in successfully following the password reset.
How can I do this?
Thanks
- Lloyd Silver
- June 08, 2014
- Like
- 0
Force.com site / SSO Session Timeout
I have a Force.com site using authenticated website licenses. In addition, I'm using SFDC as an identity provider for users to login to a WordPress site that is a service provider. Users start with the WordPress site and then when trying to login there are redirected to a visualforce login page where they are authenticated and returned to the WordPress site - now being a logged in user on both the WP and force.com sites.
If the user closes their browser, they are logged off from both sites.
If they log out of the WP site they are still logged in to the force.com site until they logout over there, or close their browser.
Ideally, they would stay logged in to at least the WordPress site for a longer period of time. And then if they try to access one of the pages in the force.com site (where I'm okay with shorter logout periods) they would be asked to enter their login credentials if that session has expired.
Is this possible?
Any way of allowing the service provider (WordPress in this case) to stay in logged in status for a period of time even if the browser window is closed?
Thanks
If the user closes their browser, they are logged off from both sites.
If they log out of the WP site they are still logged in to the force.com site until they logout over there, or close their browser.
Ideally, they would stay logged in to at least the WordPress site for a longer period of time. And then if they try to access one of the pages in the force.com site (where I'm okay with shorter logout periods) they would be asked to enter their login credentials if that session has expired.
Is this possible?
Any way of allowing the service provider (WordPress in this case) to stay in logged in status for a period of time even if the browser window is closed?
Thanks
- Lloyd Silver
- June 08, 2014
- Like
- 0
Using a more "normal" date entry field for date range on filter
This is a force.com page that has two date fields used to define a date range to lookup records to display. I want the user to be able to enter a simple date in a format such as MM/DD/YY instead of how it is currently. I've got no clue how to fix this if you could help. Thanks.
CONTROLLER
PAGE
CONTROLLER
public with sharing class EstimateCommList { public list<Data_Estimated_Comm> LDEC {get;set;} public User user; public String curruserid; public String CId; public String sort_by {get;set;} public Date from_date {get;set;} public Date to_date {get;set;} public EstimateCommList() { curruserid = UserInfo.getUserId(); system.debug('curruserid:'+curruserid); //get user record with contact__c user = [Select u.Name, u.Id, u.ContactId From User u where u.Id =:curruserid]; CId = user.ContactId; system.debug('CId:'+CId); from_date = System.today(); to_date = System.today().addMonths(6); /* from_date = System.now().addHours(0); String SStartDT = from_date.formatGMT('yyyy-MM-dd') + 'T' + StartDT.formatGMT('HH:mm:ss.SSS') + 'Z'; to_date = System.now().addHours(4); String SEndDT = to_date.formatGMT('yyyy-MM-dd') + 'T' + EndDT.formatGMT('HH:mm:ss.SSS') + 'Z'; system.debug('from_date: '+from_date+ 'to_date: '+to_date); */ list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name, e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name, e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name From Estimated_Commissions__c e where e.Agent__c =:CId order by CreatedDate desc limit 10 ]; system.debug('LEC:'+LEC); if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c EC : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = EC.Agency__r.Name; DEC.Agent = EC.Agent__r.Name; DEC.Casesplit = EC.Case_Split__c; DEC.ExcessCommAmt = EC.Excess_Commission_amount__c; DEC.ExcessCommRate = EC.Excess_Commission_Rate__c; DEC.FYCAmt = EC.FYC_Amount__c; DEC.FYCRate = EC.FYC_Rate__c; DEC.Insurance_Commission_Name = EC.Name; DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name; DEC.Product = EC.Insurance_Case__r.Product__r.Name; DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c; DEC.Premium = EC.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = EC.Valid_From__c; LDEC.add(DEC); } } public List<SelectOption> getSort() { List<SelectOption> options1 = new List<SelectOption>(); options1.add(new SelectOption('Valid_From__c','Date')); options1.add(new SelectOption('Agent__r.Name','Agent Name')); options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier')); options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business')); options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product')); options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number')); options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client')); options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode')); options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium')); options1.add(new SelectOption('FYC_Rate__c','FYC Rate')); options1.add(new SelectOption('FYC_Amount__c','FYC Amount')); options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate')); options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount')); return options1; } public void searchEsti() { List<Estimated_Commissions__c> LEC = new List<Estimated_Commissions__c>{}; String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,'; DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,'; DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; DB1 += 'e.Insurance_Case__r.Policy_Number__c, '; DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name'; DB1 += 'From Estimated_Commissions__c e '; DB1 += ' where e.Agent__c =:CId '; DB1 += ' and e.Valid_From__c >= '+from_date; DB1 += ' and e.Valid_From__c <= '+to_date; DB1 += ' order by '+ sort_by + ' asc ' ; DB1 += ' limit 10'; LEC = DataBase.query(DB1); system.debug('LEC:'+LEC); LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c est : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = est.Agency__r.Name; DEC.Agent = est.Agent__r.Name; DEC.Casesplit = est.Case_Split__c; DEC.ExcessCommAmt = est.Excess_Commission_amount__c; DEC.ExcessCommRate = est.Excess_Commission_Rate__c; DEC.FYCAmt = est.FYC_Amount__c; DEC.FYCRate = est.FYC_Rate__c; DEC.Insurance_Commission_Name = est.Name; DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name; DEC.Product = est.Insurance_Case__r.Product__r.Name; DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c; DEC.Premium = est.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = est.Valid_From__c; LDEC.add(DEC); } } }
PAGE
<apex:page controller="EstimateCommList" showHeader="false" standardStylesheets="true"> <!-- The site template provides layout & style for the site --> <apex:composition template="{!$Site.Template}"> <apex:define name="body"> <apex:form style="position:relative;top:50px;margin-left:25px;" > <div style="width:1200px;margin-left:20px;"> <apex:pageBlock title="Estimated Commission List"> <apex:pageblockSection title="Search Section" columns="2" > <apex:outputText value="Date Range " style="margin-left:100px;"></apex:outputText> <apex:inputText value="{!from_date}" style="margin-left:20px; width:155px;"></apex:inputText> <apex:outputText value="To" style="margin-left:20px; display: block; text-align: right;"></apex:outputText> <apex:inputText value="{!to_date}" style="margin-left:20px; width:155px;"></apex:inputText> <apex:outputText value="Sort by" style="margin-left:100px;"></apex:outputText> <apex:selectList value="{!sort_by}" id="sort1" multiselect="false" size="1" style="padding-left: 30px;"> <apex:selectOptions value="{!Sort}" /> </apex:selectList> <apex:commandButton style="width:75px;margin-left:250px;" action="{!searchEsti}" value="Search"/> </apex:pageblockSection> <apex:pageBlockTable value="{!LDEC}" var="e" id="instancesTable"> <apex:column > <apex:facet name="header"> Date</apex:facet> <apex:outputText value="{0,date,MM'/'dd'/'yyyy }"> <apex:param value="{!e.Valid_From}" /> </apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Agent Name</apex:facet> <apex:outputText value="{!e.Agent}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Carrier</apex:facet> <apex:outputText value="{!e.Carrier}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Line Of Business</apex:facet> <apex:outputText value="{!e.LineOfBusiness}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Product</apex:facet> <apex:outputText value="{!e.Product}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Policy Number</apex:facet> <apex:outputText value="{!e.PolicyNumber}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Client</apex:facet> <apex:outputText value="{!e.Client}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Premium Mode</apex:facet> <apex:outputText value="{!e.PremiumMode}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Premium</apex:facet> <apex:outputText value="{!e.Premium}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> FYC Rate</apex:facet> <apex:outputText value="{!e.FYCRate}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> FYC Amount</apex:facet> <apex:outputText value="{!e.FYCAmt}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Rate </apex:facet> <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Amount </apex:facet> <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText> </apex:column> <!-- <apex:column > <apex:facet name="header"> Insurance Commission Name</apex:facet> <apex:outputText value="{!e.Insurance_Commission_Name}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Agency</apex:facet> <apex:outputText value="{!e.Agency}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Case split</apex:facet> <apex:outputText value="{!e.Casesplit}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Commission amount</apex:facet> <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Commission Rate</apex:facet> <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText> </apex:column> --> </apex:pageBlockTable> </apex:pageBlock> </div> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> </apex:form> </apex:define> </apex:composition> </apex:page>
- Lloyd Silver
- May 23, 2014
- Like
- 0
SOQL on lookup object and if statement
I have an existing page for a force.com site created to output a list of items from a custom object (Carrier_Product_Commission_Level__c). It works perfectly except that I want to filter the items it returns by a field on a lookup object.
So Carrier_Product_Commission_Level__c has Carrier_Product__c as a lookup object. Carrier_Product__c has a checkbox field called Inactive__c. And I want to only return those Carrier_Product_Commission_Level__c that have a Carrier_Product__c which in turn has a false value for Inactive__c.
I suspect I need an additional SOQL statement and If statement. I've been playing around with it but failing.
I appreciate some help in figuring this out. Thanks.
So Carrier_Product_Commission_Level__c has Carrier_Product__c as a lookup object. Carrier_Product__c has a checkbox field called Inactive__c. And I want to only return those Carrier_Product_Commission_Level__c that have a Carrier_Product__c which in turn has a false value for Inactive__c.
I suspect I need an additional SOQL statement and If statement. I've been playing around with it but failing.
I appreciate some help in figuring this out. Thanks.
public with sharing class Carrier_Product_Commission { public list<Carrier_Product_Commission_Level__c> CPCL {get;set;} public string Product {get;set;} public decimal Excess_Commission_Rate {get;set;} public decimal Commission_Rate {get;set;} public String CurrentUserId {get;set;} public list<Data_Carrier_Product> LDCP {get;set;} public Carrier_Product_Commission() { if(System.currentPageReference().getParameters().get('aid') != null){ CurrentUserId = System.currentPageReference().getParameters().get('aid'); } System.debug('CurrentUserId :'+CurrentUserId); // Get all Carrier_Product_Commission_Level list related to this Commission_Level CPCL = [Select c.Product__c, c.Excess_Commission_Rate__c, c.Product__r.Name, c.Commission_Rate__c, c.Carrier_Commission_Level__r.Id From Carrier_Product_Commission_Level__c c where c.Carrier_Commission_Level__r.Id =: CurrentUserId order by CreatedDate desc limit 30]; System.debug('CPCL :'+CPCL); if (LDCP == null) LDCP = new List<Data_Carrier_Product> {}; for(Carrier_Product_Commission_Level__c cp : CPCL) { Data_Carrier_Product DC = new Data_Carrier_Product(); DC.Product = cp.Product__r.Name; DC.Excess_Commission_Rate = cp.Excess_Commission_Rate__c; DC.Commission_Rate = cp.Commission_Rate__c; LDCP.add(DC); } } }
- Lloyd Silver
- May 23, 2014
- Like
- 0
SFDC as identity provider - login cookie
I'm using SFDC as an identity provider for a SAML logon to a WordPress site. As of now, each time a user closes his browser they have to log back in. Is there any way of setting a cookie so that they remain in a logged in status for a longer period of time?
- Lloyd Silver
- July 03, 2014
- Like
- 1
Please help bulkify this trigger
My incredibly rudimentary SFDC coding skills came up with the trigger below but it's resulting in "too many SOQL queries" errors. I'd appreciate some help bulkifying it.
Thanks.
Thanks.
trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) { Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>(); Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>(); Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0]; for(Insurance_Case__c record: Trigger.new){ Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id); if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){ casesstatus.put(record.Id, record); } else { cases.put(record.Id, record); } } Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract']; Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract']; for(Agent_Cases_Commissions__c acc :accstatus){ acc.Case_Status_Change__c = TRUE; accToUpdate.add(acc); } for(Agent_Cases_Commissions__c acc2 :accnostatus){ accToUpdate.add(acc2); } if(!accToUpdate.isEmpty()) update accToUpdate; }
- Lloyd Silver
- September 19, 2014
- Like
- 0
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '"
I had someone edit a class and unfortunately they've gone missing and I'm getting an error when deploying:
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
public without sharing class EstimateCommList { public list<Data_Estimated_Comm> LDEC {get;set;} public User user; public String curruserid; public String CId; public String sort_by {get;set;} public Date from_date {get;set;} public Date to_date {get;set;} public string fromdate{get; set;} public string todate{get; set;} public map<string,List<string>> JuniorContactsMap; public String User_Selection{get;set;} public Boolean IsEmptyList{get;set;} public List<string> cLst; public Boolean hasAgencyAccess{get;set;} public Boolean IsAgency{get;set;} public map<string,string> AccountMap; public Date StartingDate; public EstimateCommList() { curruserid = UserInfo.getUserId(); system.debug('curruserid:'+curruserid); //get user record with contact__c user = [Select u.Name, u.Id, u.ContactId,u.contact.accountid,u.contact.Agency_Commission_Access__c From User u where u.Id =:curruserid]; CId = user.ContactId; if(user.contact.Agency_Commission_Access__c==true){ hasAgencyAccess=true; } else{ hasAgencyAccess=false; } IsAgency=false; if(test.isrunningtest()){ User_Selection=CId; } system.debug('CId:'+CId); //Added for Datepicker variale convertion into date time. fromdate=string.valueOf(string.valueOf(System.today().month()+'/'+System.today().day()+'/'+System.today().year())); system.debug('@@@@@@@@@@'+fromdate); todate= string.valueOf(System.today().addmonths(6).month()+'/'+System.today().addmonths(6).day()+'/'+System.today().addmonths(6).year()); system.debug('@@@@@@@@@@'+todate); IsEmptyList=false; system.debug('**************'+IsEmptyList); JuniorContactsMap=new map<string,List<string>>(); for(contact g:[select id,name,ReportsToId from contact]){ if(JuniorContactsMap.containskey(g.ReportsToId)){ JuniorContactsMap.get(g.ReportsToId).add(g.id); } else{ list<string> temp=new List<string>(); temp.add(g.id); JuniorContactsMap.put(g.ReportsToId,temp); } } system.debug('################'+JuniorContactsMap); cLst=new List<string>(); cLst.add(CId); List<string> cLst1=new List<string>(); cLst1.add(CId); List<string> TList=new List<string>(); TList.add('Test'); while(TList.size() >=1){ system.debug('^^^^^^^^^^^^^^^^^'+cLst1); List<string> TempConList=Childcontacts(cLst1); if(TempConList.size()>0){ cLst.addall(TempConList); cLst1=TempConList; } else{ TList.remove(0); } } system.debug('***************'+cLst); StartingDate=date.newinstance(2014,7,1); system.debug('######'+StartingDate); list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, e.Insurance_Case__r.name, e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name, e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,e.Insurance_Case__r.Submitted_Date__c, e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name From Estimated_Commissions__c e where e.Agent__c =:CId AND e.Insurance_Case__r.Submitted_Date__c >=: StartingDate order by CreatedDate desc limit 1000 ]; system.debug('LEC:'+LEC); if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c EC : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = EC.Agency__r.Name; DEC.Agent = EC.Agent__r.Name; DEC.Casesplit = EC.Case_Split__c; DEC.ExcessCommAmt = EC.Excess_Commission_amount__c; DEC.ExcessCommRate = EC.Excess_Commission_Rate__c; DEC.FYCAmt = EC.FYC_Amount__c; DEC.FYCRate = EC.FYC_Rate__c; DEC.Insurance_Commission_Name = EC.Name; DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name; DEC.Product = EC.Insurance_Case__r.Product__r.Name; DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c; DEC.Premium = EC.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = EC.Valid_From__c; //new changes DEC.InsuranceCase= EC.Insurance_Case__c; DEC.InsuranceCaseName= EC.Insurance_Case__r.Name; LDEC.add(DEC); } } public List<SelectOption> getSort() { List<SelectOption> options1 = new List<SelectOption>(); options1.add(new SelectOption('Valid_From__c','Date')); options1.add(new SelectOption('Agent__r.Name','Agent Name')); options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier')); options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business')); options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product')); options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number')); options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client')); options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode')); options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium')); options1.add(new SelectOption('FYC_Rate__c','FYC Rate')); options1.add(new SelectOption('FYC_Amount__c','FYC Amount')); options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate')); options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount')); return options1; } //Method which will call each time for inner hierarchy of contacts public List<string> Childcontacts(List<string> CurrentContactsIDList){ List<string> d=new List<string>(); for(string w:CurrentContactsIDList){ system.debug('%%%%%%%%%%%%%%%'+w+'-'+JuniorContactsMap.get(w)); if(JuniorContactsMap.containskey(w)){ for(string l:JuniorContactsMap.get(w)){ d.add(l); } } } return d; } //Method which will have all users list in hierarchy of user logged in public List<SelectOption> getAllusers() { List<SelectOption> options1 = new List<SelectOption>(); AccountMap=new MAp<string,string>(); integer i=0; List<contact> mylst=[select id,name,accountid from contact where id IN:cLst]; for(contact w:[select id,name,accountid from contact where id IN:cLst]){ AccountMap.put(w.id,w.accountid); if(w.id==CId){ contact q=mylst[0]; mylst[0]=mylst[i]; mylst[i]=q; } i++; } system.debug('###############'+AccountMap); for(contact c:mylst){ options1.add(new SelectOption(c.id,c.name)); } return options1; } public pagereference searchEsti() { List<Estimated_Commissions__c> LEC = new List<Estimated_Commissions__c>{}; //New chanages as part of input date picker format changes Datetime Dt1; string Dt2; Datetime Dt3; string Dt4; system.debug('##############'+fromdate+'-'+todate); if(fromdate !=null && fromdate !=''){ List<string> a=fromdate.split('/'); Dt1=Datetime.newinstance(integer.valueOf(a[2]),integer.valueOf(a[0]),integer.valueOf(a[1])); Dt2=Dt1.format('yyyy-MM-dd'); } else{ Dt2=null; } if(todate !=null && todate !=''){ List<string> b=todate.split('/'); Dt3=Datetime.newinstance(integer.valueOf(b[2]),integer.valueOf(b[0]),integer.valueOf(b[1])); Dt4=Dt3.format('yyyy-MM-dd'); } else{ Dt4=null; } system.debug('######'+Dt2+'-'+Dt4); String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,e.Insurance_Case__r.name,'; DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,'; DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; DB1 += 'e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Submitted_Date__c, '; DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name'; DB1 += ' From Estimated_Commissions__c e '; if(IsAgency==false){ DB1 += ' where e.Agent__c =\''+User_Selection+'\''; } else if(IsAgency==true){ //DB1 += ' where e.Agency__c =\''+AccountMap.get(User_Selection)+'\''; DB1 += ' where e.Agency__c =\''+user.Contact.accountId+'\''; } //New changes as part of input date chaanges DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= '+ StartingDate; if(Dt2!=null){ DB1 += ' and e.Valid_From__c >= ' + Dt2; } if(Dt4!=null){ DB1 += ' and e.Valid_From__c <= ' + Dt4; } DB1 += ' order by '+ sort_by + ' asc ' ; DB1 += ' limit 10'; system.debug('#################'+DB1); LEC = DataBase.query(DB1); system.debug('LEC:'+LEC); LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c est : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = est.Agency__r.Name; DEC.Agent = est.Agent__r.Name; DEC.Casesplit = est.Case_Split__c; DEC.ExcessCommAmt = est.Excess_Commission_amount__c; DEC.ExcessCommRate = est.Excess_Commission_Rate__c; DEC.FYCAmt = est.FYC_Amount__c; DEC.FYCRate = est.FYC_Rate__c; DEC.Insurance_Commission_Name = est.Name; DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name; DEC.Product = est.Insurance_Case__r.Product__r.Name; DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c; DEC.Premium = est.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = est.Valid_From__c; //new changes DEC.InsuranceCase= est.Insurance_Case__c; DEC.InsuranceCaseName= est.Insurance_Case__r.Name; LDEC.add(DEC); } return null; } }
/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest(SeeAllData=false) private class TestEstimateCommListClass { static testMethod void DoListTest() { RecordType r = [Select Name, Id From RecordType where Name ='Carriers' ]; profile w = [Select Name, Id From profile where Name ='Authenticated Website' ]; Account a= new Account(); a.Name = 'atest'; a.Type = r.Name; a.RecordTypeId = r.Id; system.debug('a:'+a); insert a; contact con=new contact(lastname='test two',accountid=a.id,Email='client321@mixcimizer.com'); insert con; User u = new User(); u.Username = 'cooks@gmail.com'; u.LastName = 'mycook'; u.Email = 'client321@mixcimizer.com'; u.profileid = w.id; u.contactid = con.id; u.alias =u.LastName.substring(0,4); u.CommunityNickname ='4321new'; u.MobilePhone ='9875643456'; u.TimeZoneSidKey = 'Asia/Kolkata'; u.LocaleSidKey = 'en_IE_EURO'; u.EmailEncodingKey = 'ISO-8859-1'; u.LanguageLocaleKey = 'en_US'; u.IsActive = true; INSERT U; Carrier_Product__c p = new Carrier_Product__c(); p.Name = 'ptest'; p.Carrier__c = a.Id; p.Line_of_Business__c = 'Life Insurance'; p.Plan_Type__c = 'Term Life Insurance'; insert p; Insurance_Case__c ic = new Insurance_Case__c(); ic.Carrier__c = a.Id; ic.Product__c = p.Id; ic.X1035_Exchange_Amount__c = 1000; ic.X1035_Exchange_Carrier__c = 'test'; ic.Approved_Rating_Additional_Insured__c = 'test'; ic.Approved_Rating_Primary_Insured__c = 'test'; ic.Elimination_Period__c = ''; ic.Excess_Premium__c = 1000; ic.Face_Amount__c = 500; ic.Line_of_Business__c = 'Life Insurance'; ic.Lump_Sum_Amount__c = 500; ic.Modal_Premium__c = 1000; ic.Policy_Number__c = '123'; ic.Premium_Mode__c = 'Monthly'; ic.Premium_Payment_Method__c = ''; ic.Policy_Date__c = system.today(); ic.Proposed_Face_Amount__c = 100; ic.Proposed_Premium__c = 100; ic.Proposed_Type_Of_Insurance__c = ''; ic.Rating_Applied_For_Additional_Insured__c = ''; ic.Rating_Applied_For_Primary_Insured__c = ''; ic.Source_of_Funds__c = ''; ic.State_of_Issue__c = 'Alabama'; ic.Status__c = 'Inforce'; ic.Target_Premium__c = 1000; insert ic; ic.X1035_Exchange_Amount__c = 2000; ic.X1035_Received_Date__c = system.today(); ic.X1035_Received__c = true; ic.Lump_Sum_Amount__c = 400; ic.Lump_Sum_Received__c = true; ic.Lump_Sum_Received_Date__c = system.today(); update ic; Estimated_Commissions__c e = new Estimated_Commissions__c(); e.Insurance_Case__c = ic.id; e.agent__c=con.id; insert e; system.runas(u){ EstimateCommList ecl = new EstimateCommList(); ecl.getAllusers(); ecl.getSort(); ecl.sort_by='Valid_From__c'; ecl.searchEsti(); Data_Estimated_Comm Dec = new Data_Estimated_Comm(); EstimateCommList ec2 = new EstimateCommList(); ec2.getAllusers(); ec2.getSort(); ec2.sort_by='Valid_From__c'; ec2.searchEsti(); } } }
- Lloyd Silver
- June 30, 2014
- Like
- 0
Force.com Site Login Redirect To External URL
I have a force.com site using authenticated website licenses along with SFDC setup as an identity provider for authentication on a WordPress site.
Users initiate login on the WordPress site at which point they are forwarded to a visualforce page where they can login, and then are redirected back to the WordPress site where they can access protected pages on the WordPress site as well as the force.com site pages.
Login via a visualforce page and then back to the WordPress site is required because of limitations with the authenticated website user license.
Everything works perfectly with one exception.
If the user has forgotten their password, they can click the forgot password link on the visualforce page. They complete the password reset process and are logged into the force.com site.
However, the single signon functionality was interrupted in the process.
So if they try to access the WordPress site's protected pages, they are asked to login again.
The only way I can get around this, as far as I can tell, is to redirect the user to an external URL (on the WordPress site) after they have logged in successfully following the password reset.
How can I do this?
Thanks
Users initiate login on the WordPress site at which point they are forwarded to a visualforce page where they can login, and then are redirected back to the WordPress site where they can access protected pages on the WordPress site as well as the force.com site pages.
Login via a visualforce page and then back to the WordPress site is required because of limitations with the authenticated website user license.
Everything works perfectly with one exception.
If the user has forgotten their password, they can click the forgot password link on the visualforce page. They complete the password reset process and are logged into the force.com site.
However, the single signon functionality was interrupted in the process.
So if they try to access the WordPress site's protected pages, they are asked to login again.
The only way I can get around this, as far as I can tell, is to redirect the user to an external URL (on the WordPress site) after they have logged in successfully following the password reset.
How can I do this?
Thanks
- Lloyd Silver
- June 08, 2014
- Like
- 0
Using a more "normal" date entry field for date range on filter
This is a force.com page that has two date fields used to define a date range to lookup records to display. I want the user to be able to enter a simple date in a format such as MM/DD/YY instead of how it is currently. I've got no clue how to fix this if you could help. Thanks.
CONTROLLER
PAGE
CONTROLLER
public with sharing class EstimateCommList { public list<Data_Estimated_Comm> LDEC {get;set;} public User user; public String curruserid; public String CId; public String sort_by {get;set;} public Date from_date {get;set;} public Date to_date {get;set;} public EstimateCommList() { curruserid = UserInfo.getUserId(); system.debug('curruserid:'+curruserid); //get user record with contact__c user = [Select u.Name, u.Id, u.ContactId From User u where u.Id =:curruserid]; CId = user.ContactId; system.debug('CId:'+CId); from_date = System.today(); to_date = System.today().addMonths(6); /* from_date = System.now().addHours(0); String SStartDT = from_date.formatGMT('yyyy-MM-dd') + 'T' + StartDT.formatGMT('HH:mm:ss.SSS') + 'Z'; to_date = System.now().addHours(4); String SEndDT = to_date.formatGMT('yyyy-MM-dd') + 'T' + EndDT.formatGMT('HH:mm:ss.SSS') + 'Z'; system.debug('from_date: '+from_date+ 'to_date: '+to_date); */ list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name, e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name, e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name From Estimated_Commissions__c e where e.Agent__c =:CId order by CreatedDate desc limit 10 ]; system.debug('LEC:'+LEC); if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c EC : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = EC.Agency__r.Name; DEC.Agent = EC.Agent__r.Name; DEC.Casesplit = EC.Case_Split__c; DEC.ExcessCommAmt = EC.Excess_Commission_amount__c; DEC.ExcessCommRate = EC.Excess_Commission_Rate__c; DEC.FYCAmt = EC.FYC_Amount__c; DEC.FYCRate = EC.FYC_Rate__c; DEC.Insurance_Commission_Name = EC.Name; DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name; DEC.Product = EC.Insurance_Case__r.Product__r.Name; DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c; DEC.Premium = EC.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = EC.Valid_From__c; LDEC.add(DEC); } } public List<SelectOption> getSort() { List<SelectOption> options1 = new List<SelectOption>(); options1.add(new SelectOption('Valid_From__c','Date')); options1.add(new SelectOption('Agent__r.Name','Agent Name')); options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier')); options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business')); options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product')); options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number')); options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client')); options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode')); options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium')); options1.add(new SelectOption('FYC_Rate__c','FYC Rate')); options1.add(new SelectOption('FYC_Amount__c','FYC Amount')); options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate')); options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount')); return options1; } public void searchEsti() { List<Estimated_Commissions__c> LEC = new List<Estimated_Commissions__c>{}; String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,'; DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,'; DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; DB1 += 'e.Insurance_Case__r.Policy_Number__c, '; DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name'; DB1 += 'From Estimated_Commissions__c e '; DB1 += ' where e.Agent__c =:CId '; DB1 += ' and e.Valid_From__c >= '+from_date; DB1 += ' and e.Valid_From__c <= '+to_date; DB1 += ' order by '+ sort_by + ' asc ' ; DB1 += ' limit 10'; LEC = DataBase.query(DB1); system.debug('LEC:'+LEC); LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c est : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = est.Agency__r.Name; DEC.Agent = est.Agent__r.Name; DEC.Casesplit = est.Case_Split__c; DEC.ExcessCommAmt = est.Excess_Commission_amount__c; DEC.ExcessCommRate = est.Excess_Commission_Rate__c; DEC.FYCAmt = est.FYC_Amount__c; DEC.FYCRate = est.FYC_Rate__c; DEC.Insurance_Commission_Name = est.Name; DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name; DEC.Product = est.Insurance_Case__r.Product__r.Name; DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c; DEC.Premium = est.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = est.Valid_From__c; LDEC.add(DEC); } } }
PAGE
<apex:page controller="EstimateCommList" showHeader="false" standardStylesheets="true"> <!-- The site template provides layout & style for the site --> <apex:composition template="{!$Site.Template}"> <apex:define name="body"> <apex:form style="position:relative;top:50px;margin-left:25px;" > <div style="width:1200px;margin-left:20px;"> <apex:pageBlock title="Estimated Commission List"> <apex:pageblockSection title="Search Section" columns="2" > <apex:outputText value="Date Range " style="margin-left:100px;"></apex:outputText> <apex:inputText value="{!from_date}" style="margin-left:20px; width:155px;"></apex:inputText> <apex:outputText value="To" style="margin-left:20px; display: block; text-align: right;"></apex:outputText> <apex:inputText value="{!to_date}" style="margin-left:20px; width:155px;"></apex:inputText> <apex:outputText value="Sort by" style="margin-left:100px;"></apex:outputText> <apex:selectList value="{!sort_by}" id="sort1" multiselect="false" size="1" style="padding-left: 30px;"> <apex:selectOptions value="{!Sort}" /> </apex:selectList> <apex:commandButton style="width:75px;margin-left:250px;" action="{!searchEsti}" value="Search"/> </apex:pageblockSection> <apex:pageBlockTable value="{!LDEC}" var="e" id="instancesTable"> <apex:column > <apex:facet name="header"> Date</apex:facet> <apex:outputText value="{0,date,MM'/'dd'/'yyyy }"> <apex:param value="{!e.Valid_From}" /> </apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Agent Name</apex:facet> <apex:outputText value="{!e.Agent}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Carrier</apex:facet> <apex:outputText value="{!e.Carrier}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Line Of Business</apex:facet> <apex:outputText value="{!e.LineOfBusiness}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Product</apex:facet> <apex:outputText value="{!e.Product}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Policy Number</apex:facet> <apex:outputText value="{!e.PolicyNumber}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Client</apex:facet> <apex:outputText value="{!e.Client}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Premium Mode</apex:facet> <apex:outputText value="{!e.PremiumMode}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Premium</apex:facet> <apex:outputText value="{!e.Premium}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> FYC Rate</apex:facet> <apex:outputText value="{!e.FYCRate}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> FYC Amount</apex:facet> <apex:outputText value="{!e.FYCAmt}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Rate </apex:facet> <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Amount </apex:facet> <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText> </apex:column> <!-- <apex:column > <apex:facet name="header"> Insurance Commission Name</apex:facet> <apex:outputText value="{!e.Insurance_Commission_Name}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Agency</apex:facet> <apex:outputText value="{!e.Agency}" ></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Case split</apex:facet> <apex:outputText value="{!e.Casesplit}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Commission amount</apex:facet> <apex:outputText value="{!e.ExcessCommAmt}"></apex:outputText> </apex:column> <apex:column > <apex:facet name="header"> Excess Commission Rate</apex:facet> <apex:outputText value="{!e.ExcessCommRate}"></apex:outputText> </apex:column> --> </apex:pageBlockTable> </apex:pageBlock> </div> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> </apex:form> </apex:define> </apex:composition> </apex:page>
- Lloyd Silver
- May 23, 2014
- Like
- 0
SOQL on lookup object and if statement
I have an existing page for a force.com site created to output a list of items from a custom object (Carrier_Product_Commission_Level__c). It works perfectly except that I want to filter the items it returns by a field on a lookup object.
So Carrier_Product_Commission_Level__c has Carrier_Product__c as a lookup object. Carrier_Product__c has a checkbox field called Inactive__c. And I want to only return those Carrier_Product_Commission_Level__c that have a Carrier_Product__c which in turn has a false value for Inactive__c.
I suspect I need an additional SOQL statement and If statement. I've been playing around with it but failing.
I appreciate some help in figuring this out. Thanks.
So Carrier_Product_Commission_Level__c has Carrier_Product__c as a lookup object. Carrier_Product__c has a checkbox field called Inactive__c. And I want to only return those Carrier_Product_Commission_Level__c that have a Carrier_Product__c which in turn has a false value for Inactive__c.
I suspect I need an additional SOQL statement and If statement. I've been playing around with it but failing.
I appreciate some help in figuring this out. Thanks.
public with sharing class Carrier_Product_Commission { public list<Carrier_Product_Commission_Level__c> CPCL {get;set;} public string Product {get;set;} public decimal Excess_Commission_Rate {get;set;} public decimal Commission_Rate {get;set;} public String CurrentUserId {get;set;} public list<Data_Carrier_Product> LDCP {get;set;} public Carrier_Product_Commission() { if(System.currentPageReference().getParameters().get('aid') != null){ CurrentUserId = System.currentPageReference().getParameters().get('aid'); } System.debug('CurrentUserId :'+CurrentUserId); // Get all Carrier_Product_Commission_Level list related to this Commission_Level CPCL = [Select c.Product__c, c.Excess_Commission_Rate__c, c.Product__r.Name, c.Commission_Rate__c, c.Carrier_Commission_Level__r.Id From Carrier_Product_Commission_Level__c c where c.Carrier_Commission_Level__r.Id =: CurrentUserId order by CreatedDate desc limit 30]; System.debug('CPCL :'+CPCL); if (LDCP == null) LDCP = new List<Data_Carrier_Product> {}; for(Carrier_Product_Commission_Level__c cp : CPCL) { Data_Carrier_Product DC = new Data_Carrier_Product(); DC.Product = cp.Product__r.Name; DC.Excess_Commission_Rate = cp.Excess_Commission_Rate__c; DC.Commission_Rate = cp.Commission_Rate__c; LDCP.add(DC); } } }
- Lloyd Silver
- May 23, 2014
- Like
- 0
Any way to bulkify a flow trigger?
I am part of the flow trigger pilot.
I have a custom object that tracks parts on a bill of materials (product parts). I have another object that tracks a simple production forecast for the products (MRP Forecast) - I have built a flow trigger that evaluates the MRP forecast and creates individual requirements records on a 3rd custom object that is Master Detail to the forecast object for each product on the bill of materials for the product specified in the forecast. (Bills of Material can be anywhere from 1 to 200 part numbers)
It works perfectly if I add or edit a forecast in the native salesforce interface - but we have hundreds of products, and each product needs a separate forecast for each month - so I need to be able to upload my forecast records en mass.
I tried an upload of 30 forecast records and it failed on the record insert: "common.exception.ApiException: record limit reached. cannot submit more than 200 records into this call".
Is there anyway I can "bulkify" the flow so that it collects multiple requests and handles them more elegantly?
Thanks!
-R
I have a custom object that tracks parts on a bill of materials (product parts). I have another object that tracks a simple production forecast for the products (MRP Forecast) - I have built a flow trigger that evaluates the MRP forecast and creates individual requirements records on a 3rd custom object that is Master Detail to the forecast object for each product on the bill of materials for the product specified in the forecast. (Bills of Material can be anywhere from 1 to 200 part numbers)
It works perfectly if I add or edit a forecast in the native salesforce interface - but we have hundreds of products, and each product needs a separate forecast for each month - so I need to be able to upload my forecast records en mass.
I tried an upload of 30 forecast records and it failed on the record insert: "common.exception.ApiException: record limit reached. cannot submit more than 200 records into this call".
Is there anyway I can "bulkify" the flow so that it collects multiple requests and handles them more elegantly?
Thanks!
-R
- PAX Admin
- May 06, 2014
- Like
- 0