zhangzhengmei
2023-08-07 5f8c97f8716088019ad9a0302c5dea461bc668b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { NavigationMixin } from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
 
import init from '@salesforce/apex/LexCICInputSolutionController.initNewCICContact';
 
 
 
 
 
export default class lexNewCICContact extends LightningElement {
    IsLoading = true;
    @api recordId;
    initData = {};
    def_account_id = '';
    RecordType = '';
 
     @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
         if (currentPageReference) {
           const urlValue = currentPageReference.state.recordId;
           if (urlValue) {
             let str = `${urlValue}`;
 
             this.recordId = str;
           }
         }
     }
     connectedCallback(){
        // this.recordId ='0030l00000wy2IgAAI';
        init({
            recordId: this.recordId
        }).then(result => {
            if (result != null) {
                console.log(result);
                this.initData = result;
                if(result !=null) {
                    if(result.contactList.length>0) {
                        if(result.contactList[0].RecordTypeId == result.contactRecordType) {
                            this.def_account_id = result.contactList[0].Account.Id;
                        } else {
                            this.def_account_id = result.contactList[0].Account.Parent_Parent__c;
                        }
 
                    }
                    this.RecordType = result.caseRecordType;                   
                }
                this.cancelSubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });            
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    async cancelSubmit(){
        // this.navigateToNewObjectPage();
        window.open('/apex/NewAndEditCase?retURL='+this.recordId+'&def_contact_id='+this.recordId+'&def_account_id='+this.def_account_id+'&RecordType='+this.RecordType);
    }
 
 
    navigateToNewObjectPage() {
        alert();
        const defaultFieldValues =encodeDefaultFieldValues({
          retURL: this.recordId,
          def_contact_id: this.recordId,
          def_account_id: this.def_account_id,
          RecordType: this.RecordType    
        });
 
        this[NavigationMixin.Navigate]({
              type: 'standard__objectPage',
              attributes: {
                objectApiName: 'Case',
                actionName: 'new'
              },
              state: {
                nooverride: '1',
                defaultFieldValues: defaultFieldValues
              }
        });
        this.dispatchEvent(new CloseActionScreenEvent());
      }
 
 
 
}
 
//old js 
// /500/e?retURL=%2F{!Contact.Id}&def_contact_id={!Contact.Id}&
// def_account_id={!IF(Contact.RecordTypeId='01210000000QfWi',Account.Id,Account.Parent_Parent__c)}
// &RecordType=01210000000QsYp&ent=Case
 
//01210000000QfWi: select Id,DeveloperName from RecordType where  SobjectType = 'Contact' and DeveloperName = 'Agency'
//01210000000QsYp: select Id,DeveloperName from RecordType where  SobjectType = 'Case' and DeveloperName = 'CICRecordType'