You need to sign in to do that
Don't have an account?
Create new Opportunity(Enquiry) When Checkbox is enabled
Hi,
I am trying to create a new opportunity (Enquiry) when a checkbox (Enquiry_Creator__c) is enabled . anyone please give me a advise why it's not created. Kindly Check the below code please.
************** Trigger ***********
Thanks in advance !!!
Regards,
Soundar.
I am trying to create a new opportunity (Enquiry) when a checkbox (Enquiry_Creator__c) is enabled . anyone please give me a advise why it's not created. Kindly Check the below code please.
************** Trigger ***********
Trigger VisualInsCreateEnquiry on Visual_Inspection__c (After Insert) { Set<Id> VisInsId = new Set<Id>(); List<Opportunity> oppList = New List<Opportunity>(); for(Visual_Inspection__c vi : Trigger.New){ If(vi.Enquiry_Creator__c == True){ VisInsId.add(vi.Id); system.debug('++++++Visual Inspection Id : ' + VisInsId); } } If(VisInsId.size() > 0){ System.debug('+++++++Visual Inspection Size is : ' + VisInsId.size() ); oppList = [Select id,name, Customer_Name__c, Type, Sales_Office__c, Sales_Org1__c, Plant_Type__c, Sites__c, CloseDate, StageName from Opportunity where Id IN :VisInsId AND RecordType.Name IN ('Service Centre')]; for(Visual_Inspection__c vis : Trigger.new){ If(VisInsId.size() > 0 && vis.Enquiry_Creator__c == True){ for(Opportunity op : oppList){ Opportunity oppty = New Opportunity(); //oppty.RecordTypeId = oppList.Id; oppty.Name = 'Test Oppty'; oppty.StageName = 'Enquiry'; oppty.Sales_Office__c = 'Chennai'; oppty.Sales_Org1__c = 'Chennai'; oppty.CloseDate = System.today(); oppty.Plant_Type__c = 'New Plant'; oppty.Sites__c = 'Test Site'; oppList.add(oppty); } IF(oppList.size() > 0){ insert oppList; } } } } }
Thanks in advance !!!
Regards,
Soundar.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
All Answers
While quering Opportunities at line no. 16 , see WHERE clouse , Change You are searching Opportunity ID in a Set of Visual_Inspection__c IDs , which is incorrect.
I suppose there is a field on Opportunity as Visual_Inspection__c , and your WHERE clouse should be WHERE Visual_Inspection__c IN :VisInsId
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Hi $C0RP!AN K!NG,
Thanks For Your quick response..
Actually i did one mistake !! we need to create a new Opportunity when a checkbox is true . So we need to query for visual_inspection__c ??
And I have some changes based on above Query. Now also i am getting
Error: (Incompatible element type Opportunity for collection of Visual_Inspection__c)
Regards,
Soundar.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
I have some changes in my code by your Help.. thanks a lot!!
*********** Code Chages ************
Thanks,
Soundar.