Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. let splittedURL = salesforceUrl.split('/');
  2. let lastItem = splittedURL[splittedURL.length - 1];
  3. let prelastItem = splittedURL[splittedURL.length - 2];
  4. let id = lastItem === "view" ? prelastItem : lastItem;
  5. id = id.includes('?') ? id.substr(0, id.indexOf('?')) : id;
  6.  
  7. //get oppurtutnities from salesforce and find Contract_Status__c field from there
  8. CachedOpportunity.query(function (opportunities) {
  9. let found = false;
  10. for(let i=0; i<opportunities.length; i++){
  11. let opp = opportunities[i];
  12. let minIdLength = Math.min(opp.Id.length, id.length);
  13. if (opp.Id.substring(0, minIdLength) === id.substring(0, minIdLength)) { //ID in opportunity has postfix of 3 chars
  14. if (opp.Contract_State__c) paperwork = opp.Contract_State__c;
  15. found = true;
  16. break;
  17. }
  18. }
  19. if (!found) {
  20. console.log("Paperwork status of item with ID not found:" + id);
  21. }
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement