
'System Administrator' && 'Custom Marketing Users 10K 25K' && 'Customer Service User' && 'Fulfillment User'. Where should i add these user profiles in my code.Any Suggestion plz
Code :
trigger oli_multiple_products_before_insert on OpportunityLineItem (before insert) {
for (OpportunityLineItem oli : Trigger.new) {
if (Trigger.isInsert) {
Integer line_Count = [SELECT COUNT()
FROM OpportunityLineItem o
WHERE o.OpportunityId = :oli.OpportunityId
AND o.PriceBookEntryId = :oli.PriceBookEntryId ];
if (line_Count > 0) {
oli.addError('A Product can not be added more than once to the Opportunity.');
}
}
}
}
i tried adding the profiles as
trigger oli_multiple_products_before_insert on OpportunityLineItem (before insert) {
for (OpportunityLineItem oli : Trigger.new) {
if (Trigger.isInsert) {
if(
userinfo.getProfileId() != 'System Administrator' &&
userinfo.getProfileId() !='Custom Marketing Users 10K 25K '&&
userinfo.getProfileId() !='Customer Service User'&&
userinfo.getProfileId() !='Fulfillment User'
) {
Integer line_Count = [SELECT COUNT()
FROM OpportunityLineItem o
WHERE o.OpportunityId = :oli.OpportunityId
AND o.PriceBookEntryId = :oli.PriceBookEntryId ];
if (line_Count > 0) {
oli.addError('A Product can not be added more than once to the Opportunity.');
}
}
}
}
}
But still throws an Error .I shall appreciate your help.
12 Antworten
Hi Meghna, Creating a unique text field
- Go to Setup > Build > Customize > Opportunities > Opportunity Products > Fields
- New custom field
- Choose datatype: Text and click Next
- Give it a name, and Length anything between 40 to 255
- Click Unique check box and Treat "ABC" and "abc" as different values (case sensitive) and Click Next
- Next > Save (don't add it to the layout)
Creating a workflow
- Go to Setup > Build > Create > Workflow and Approvals > Workflow Rules
- Create New Rule
- Choose object : Opportunity Product and click Next
- Give it a Name and Description
- Evaluate the rule when a record is: Created (Choose Created and Everytime its edited, to update existing records)
- Choose Formula Evaluates to True
IF(
CASE($Profile.Name ,
"System Administrator", 0,
"Custom Marketing Users 10K 25K",0,
"Customer Service User",0,
"Fulfillment User",0,
1)=1,
TRUE,
FALSE
)
- Click Save & Next
- Add Workflow Actions : New Field Update
- Update Unique text field created, with Formula
OpportunityId & PricebookEntryId
Click Save > Done > Activate
PS : You need to update existing records( either with other profile or by removing your profile from the list for some time)
Thanks
I hope it helps