Last active
August 29, 2015 14:07
-
-
Save jheth/271ab8b4ad82b2b07218 to your computer and use it in GitHub Desktop.
Salesforce: Clone QuoteLineItems from Quote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
String sourceId = '0Q0i00000019TdOCAU'; | |
String destinationId = null; //'0Q0i00000019TdTCAU'; | |
String query = 'select Quoteid, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, ListPrice, Subtotal, TotalPrice '; | |
// get all of the custom, writeable fields | |
Map<String, Schema.SObjectField> fieldMap = QuoteLineItem.getSObjectTypE().getDescribe().fields.getMap(); | |
for (String key : fieldMap.keySet()) { | |
Schema.SObjectField field = fieldMap.get(key); | |
Schema.DescribeFieldResult result = field.getDescribe(); | |
if (result.isCustom() && !result.isCalculated()) { | |
query += ' ,'+result.getName(); | |
} | |
} | |
query += ' from QuoteLineItem where QuoteId = :sourceId LIMIT 122'; | |
List<QuoteLineItem> q1List = Database.query(query); | |
for (QuoteLineItem q1 : q1List) { | |
QuoteLineItem q2 = q1.clone(); | |
if (destinationId != null) { | |
q2.QuoteId = destinationId; | |
} | |
insert q2; | |
} | |
} catch(DMLException e) { | |
System.debug(e.getMessage()); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment